Tencent/WeKnora · error
parse yuque credentials: %w
Error message
parse yuque credentials: %w
What it means
After marshalling, parseYuqueConfig unmarshals the JSON into the typed Config struct. This error wraps any json.Unmarshal failure, meaning the credentials map's shape/types do not match the Config struct (e.g. api_token is a number or object instead of a string).
Source
Thrown at internal/datasource/connector/yuque/types.go:75
url = strings.TrimRight(url, "/")
return url
}
// parseYuqueConfig extracts and validates Yuque-specific configuration.
// Uses JSON marshal/unmarshal roundtrip (consistent with Feishu's parseFeishuConfig)
// rather than single-field type assertion, because we have multiple fields with
// optional defaults.
func parseYuqueConfig(config *types.DataSourceConfig) (*Config, error) {
if config == nil {
return nil, fmt.Errorf("%w: config is nil", datasource.ErrInvalidConfig)
}
credBytes, err := json.Marshal(config.Credentials)
if err != nil {
return nil, fmt.Errorf("marshal credentials: %w", err)
}
var cfg Config
if err := json.Unmarshal(credBytes, &cfg); err != nil {
return nil, fmt.Errorf("parse yuque credentials: %w", err)
}
if strings.TrimSpace(cfg.APIToken) == "" {
return nil, fmt.Errorf("%w: api_token is required", datasource.ErrInvalidCredentials)
}
if err := datasource.ValidateConnectorBaseURL(cfg.GetBaseURL()); err != nil {
return nil, err
}
return &cfg, nil
}
// --- Yuque API response types ---
// flexibleStatus accepts either a string ("1") or a number (1) for the doc
// `status` field. Yuque's OpenAPI spec declares `status` as string, but the
// runtime API returns it as an integer, so unmarshaling into a plain string
// fails with "cannot unmarshal number into Go struct field ... of type string".
// Normalizing to the textual form lets existing comparisons (e.g. != "1") keep
// working for both response shapes.View on GitHub (pinned to 988cbb0330)
Solutions
- Ensure every credential field is the type Config expects — api_token must be a JSON string: quote it in the config file.
- Compare the credentials keys/types against the yuque Config struct definition.
- If the raw error mentions 'cannot unmarshal number into Go struct field', fix that specific field's type.
Example fix
// before (config.yml) api_token: 12345678 // after api_token: "12345678"
Defensive patterns
Strategy: validation
Validate before calling
var probe struct {
APIToken string `json:"api_token"`
}
b, _ := json.Marshal(config.Credentials)
if err := json.Unmarshal(b, &probe); err != nil {
return fmt.Errorf("credential types invalid: %w", err)
} Type guard
func validYuqueCreds(creds map[string]any) bool {
t, ok := creds["api_token"]
return ok && reflect.TypeOf(t).Kind() == reflect.String
} Try / catch
cfg, err := parseYuqueConfig(config)
if err != nil {
var typeErr *json.UnmarshalTypeError
if errors.As(err, &typeErr) {
return fmt.Errorf("field %s has wrong type", typeErr.Field)
}
return err
} Prevention
- Quote all token values in YAML/JSON config files.
- Keep credential field types consistent across config migrations.
- Round-trip credentials through the Config struct in tests.
When it happens
Trigger: config.Credentials contains fields whose JSON types are incompatible with Config (e.g. api_token as integer, or a nested object where a string is expected).
Common situations: Hand-edited YAML/JSON config where the token was quoted incorrectly; config migrations changing credential field types; API/stored credentials with unexpected types.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- args must be a string or an array of strings: %w
- logical operator %s requires an array of conditions
- failed to unmarshal condition at index %d: %w
- unmarshal page: %w
- unmarshal database: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/7095d6ecd5d2a674.
Report an issue: GitHub.