MCPcopy
hub / github.com/wavetermdev/waveterm / readConfigHelper

Function readConfigHelper

pkg/wconfig/settingsconfig.go:519–552  ·  view source on GitHub ↗
(fileName string, barr []byte, readErr error)

Source from the content-addressed store, hash-verified

517}
518
519func readConfigHelper(fileName string, barr []byte, readErr error) (waveobj.MetaMapType, []ConfigError) {
520 var cerrs []ConfigError
521 if readErr != nil && !os.IsNotExist(readErr) {
522 cerrs = append(cerrs, ConfigError{File: fileName, Err: readErr.Error()})
523 }
524 if len(barr) == 0 {
525 return nil, cerrs
526 }
527 var rtn waveobj.MetaMapType
528 err := json.Unmarshal(barr, &rtn)
529 if err != nil {
530 if syntaxErr, ok := err.(*json.SyntaxError); ok {
531 offset := syntaxErr.Offset
532 if offset > 0 {
533 offset = offset - 1
534 }
535 lineNum, colNum := utilfn.GetLineColFromOffset(barr, int(offset))
536 isTrailingComma := isTrailingCommaError(barr, int(offset))
537 if isTrailingComma {
538 err = fmt.Errorf("json syntax error at line %d, col %d: probably an extra trailing comma: %v", lineNum, colNum, syntaxErr)
539 } else {
540 err = fmt.Errorf("json syntax error at line %d, col %d: %v", lineNum, colNum, syntaxErr)
541 }
542 }
543 cerrs = append(cerrs, ConfigError{File: fileName, Err: err.Error()})
544 }
545
546 // Resolve environment variable replacements
547 if rtn != nil {
548 resolveEnvReplacements(rtn)
549 }
550
551 return rtn, cerrs
552}
553
554func readConfigFileFS(fsys fs.FS, logPrefix string, fileName string) (waveobj.MetaMapType, []ConfigError) {
555 barr, readErr := fs.ReadFile(fsys, fileName)

Callers 1

readConfigFileFSFunction · 0.85

Calls 4

GetLineColFromOffsetFunction · 0.92
isTrailingCommaErrorFunction · 0.85
resolveEnvReplacementsFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected