{"record":{"id":"d12d579d63645c3c","repo":"can1357/oh-my-pi","slug":"schema-produced-no-default-value","errorCode":null,"errorMessage":"Schema produced no default value","messagePattern":"Schema produced no default value","errorType":"exception","errorClass":"ConfigError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/config/config-file.ts","lineNumber":238,"sourceCode":"\twithValidation(name: string, validate: (value: T) => void): this {\n\t\tconst prev = this.#auxValidate;\n\t\tthis.#auxValidate = (value: T) => {\n\t\t\tprev?.(value);\n\t\t\ttry {\n\t\t\t\tvalidate(value);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new ConfigError(this.id, undefined, { err: error, stage: `Validate(${name})` });\n\t\t\t}\n\t\t};\n\t\treturn this;\n\t}\n\n\tcreateDefault(): T {\n\t\tconst parsed = this.schema({});\n\t\tif (!(parsed instanceof Error)) return parsed as T;\n\t\tconst fallback = this.schema(undefined);\n\t\tif (!(fallback instanceof Error)) return fallback as T;\n\t\tthrow new ConfigError(this.id, undefined, {\n\t\t\terr: new Error(\"Schema produced no default value\"),\n\t\t\tstage: \"createDefault\",\n\t\t});\n\t}\n\n\t#storeCache(result: LoadResult<T>): LoadResult<T> {\n\t\tthis.#cache = result;\n\t\treturn result;\n\t}\n\n\t#parseContent(content: string): LoadResult<T> {\n\t\ttry {\n\t\t\tlet parsed: unknown;\n\t\t\tconst readPath = this.#resolveReadPath();\n\t\t\tif (readPath.endsWith(\".json\") || readPath.endsWith(\".jsonc\")) {\n\t\t\t\tparsed = JSONC.parse(content);\n\t\t\t} else if (readPath.endsWith(\".yml\") || readPath.endsWith(\".yaml\")) {\n\t\t\t\tparsed = YAML.parse(content);","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/config/config-file.ts#L220-L256","documentation":"createDefault builds a default config by invoking the ArkType schema with an empty object ({}) and, failing that, with undefined. If both applications return an Error (the schema has required fields with no defaults), no default value can be synthesized and it throws a ConfigError with stage 'createDefault'. Reached via loadOrDefault/loadOrDefaultAsync when the config file is missing.","triggerScenarios":"Calling loadOrDefault/loadOrDefaultAsync when the config file does not exist, while the schema requires properties that neither `{}` nor `undefined` can satisfy — i.e. required fields without `.default(...)` or optional markers.","commonSituations":"A fresh install or wiped config directory where the library is expected to bootstrap defaults, but the schema was written with mandatory fields lacking defaults, so bootstrapping fails.","solutions":["Add default values to required fields in the schema (e.g. `foo: type(\"string\").default(\"bar\")`) so `schema({})` succeeds","Make required fields optional so `schema(undefined)` yields a fallback","If defaults can't be expressed in the schema, construct the default object manually instead of relying on loadOrDefault"],"exampleFix":"// before\nconst schema = type({ name: \"string\", port: \"number\" });\n// after\nconst schema = type({ name: type(\"string\").default(\"agent\"), port: type(\"number\").default(8080) });","handlingStrategy":"validation","validationCode":"// verify the schema can synthesize a default before relying on loadOrDefault\nconst probe = schema({});\nif (probe instanceof Error) {\n\tthrow new Error(\"Schema cannot produce defaults; add .default(...) to required fields\");\n}","typeGuard":"function schemaHasDefault(schema: Type): boolean {\n\treturn !(schema({}) instanceof Error) || !(schema(undefined) instanceof Error);\n}","tryCatchPattern":"let value: T;\ntry {\n\tvalue = configFile.createDefault();\n} catch (err) {\n\tif (err instanceof ConfigError && err.stage === \"createDefault\") {\n\t\tvalue = hardcodedFallbackDefault; // manually constructed default\n\t} else throw err;\n}","preventionTips":["Give every required field in the config schema a `.default(...)` or make it optional","Unit-test that `schema({})` succeeds for every shipped config schema","Prefer manually constructed default objects over schema-synthesized defaults when defaults are complex"],"tags":["config","schema","default-value"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}