XTLS/Xray-core · error

failed to read config file at line

Error message

failed to read config file at line 

What it means

Raised in DecodeJSONConfig when JSON decoding fails AND the byte offset of the error maps to a line/char position: the config JSON has a syntax error or type mismatch at the reported line/char. The position and the decoder error are included.

Solutions

  1. Fix the JSON at the reported line/char (watch for comments if strict mode)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at infra/conf/serial/loader.go:67 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/89c4eb83e4d4d1a6. Report an issue: GitHub.

Appendix: source

Thrown at infra/conf/serial/loader.go:67

	jsonConfig := &conf.Config{}

	jsonContent := bytes.NewBuffer(make([]byte, 0, 10240))
	jsonReader := io.TeeReader(&json_reader.Reader{
		Reader: reader,
	}, jsonContent)
	decoder := json.NewDecoder(jsonReader)

	if err := decoder.Decode(jsonConfig); err != nil {
		var pos *offset
		cause := errors.Cause(err)
		switch tErr := cause.(type) {
		case *json.SyntaxError:
			pos = findOffset(jsonContent.Bytes(), int(tErr.Offset))
		case *json.UnmarshalTypeError:
			pos = findOffset(jsonContent.Bytes(), int(tErr.Offset))
		}
		if pos != nil {
			return nil, errors.New("failed to read config file at line ", pos.line, " char ", pos.char).Base(err)
		}
		return nil, errors.New("failed to read config file").Base(err)
	}

	return jsonConfig, nil
}

// DecodeJSONConfigStrict reads standard RFC 8259 JSON without comment-stripping.
// Used for remote sources (http/https/http+unix) where the payload is produced by
// automated systems and cannot contain JSON5/JSONC extensions. Avoids the
// byte-by-byte comment stripper and TeeReader, which are significant overhead on
// large configs.
func DecodeJSONConfigStrict(reader io.Reader) (*conf.Config, error) {
	data, err := io.ReadAll(reader)
	if err != nil {
		return nil, errors.New("failed to read config file").Base(err)
	}
	jsonConfig := &conf.Config{}

View on GitHub (pinned to 7d214f8b09)