Skip to content

Return Result from Yaml.parse instead of throwing - #10224

Merged
tim-smart merged 3 commits into
v4/next-minorfrom
agent/bob/dc727a942ae8
Oct 31, 2026
Merged

tim-smart merged 3 commits into
v4/next-minorfrom
agent/bob/dc727a942ae8

Conversation

@tim-smart

@tim-smart tim-smart commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Yaml.parse was the last synchronous parser in effect/encoding that threw on bad input. It now returns Result<unknown, EncodingError>, the same way Toml.parse does.

Contract

  • Valid input gives Result.succeed with the same value as before. Merge keys, BOM/CRLF handling, anchors and scalar decoding are untouched.
  • Invalid input gives Result.fail(new EncodingError({ module: "Yaml", kind: "Decode", input, message })). message is the old SyntaxError message, including its at line N / at flow offset N suffix.
  • The whole parse runs inside one try, like Toml.parse, so it never throws for any string input.
  • The JSDoc has a Details paragraph and an import.meta.vitest example with one success and one Result.isFailure. @stability unstable and @since 4.0.0 are unchanged.

Call sites

  • cli/Primitive.ts: the yml / yaml entries use Result.getOrThrow, the same as toml. The CLI error now reads Failed to parse '.yaml' file content: EncodingError: <message> instead of SyntaxError: <message>, which is how TOML failures already read.
  • tools/openapi-generator/src/OpenApiPatch.ts: parseYamlContent maps the EncodingError to JsonPatchParseError and drops Effect.try. reason is still the parser message.
  • tools/ai-codegen tests (OpenAiGeneration, OpenRouterTranscriptions): Result.getOrThrow around the config parse.

The issue also listed ai-codegen/src/Discovery.ts, ai-codegen/src/SpecFetcher.ts and api-diff/src/Annotations.ts. All three import the npm yaml package, not effect/encoding/Yaml, so this change doesn't reach them and I left them alone.

Merging main into v4/next-minor

packages/effect/src/ai/internal/mcpSkills.ts (#10082) is only on main, so this PR can't update it. Its parseFrontmatter wraps Yaml.parse in try/catch and then checks Predicate.isObject(parsed). That still compiles against the new signature, but a Result is always an object, so every frontmatter block would come back as the serialized Result instead of the mapping. When main is next merged into v4/next-minor, it needs:

const parsed = Yaml.parse(block)
if (Result.isFailure(parsed) || !Predicate.isObject(parsed.success)) return undefined
return JSON.parse(JSON.stringify(parsed.success))

Tests

packages/effect/test/encoding/Yaml.test.ts was moved to the Result contract in the first commit, using the parse / failureMessage helpers from the Json5/Jsonc tests (#9972). Every rejection now also checks module, kind and input. The tests weren't changed in the implementation commit.

Validation

  • pnpm check, pnpm lint and pnpm jsdocs --check pass.
  • pnpm codegen leaves no diff.
  • pnpm doctest --run packages/effect/src/encoding/Yaml.ts packages/effect/src/cli/Primitive.ts passes.
  • pnpm test --run packages/effect/test/encoding packages/effect/test/cli packages/effect/test/ai: 61 files, 2640 tests pass.
  • pnpm test --run packages/tools/ai-codegen/test packages/tools/openapi-generator/test: 10 files, 174 tests pass.

Closes EFF-3201

@changeset-bot

changeset-bot Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f5c8633

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.35 KB 39.35 KB 0.00 KB (0.00%)
basic.ts 7.18 KB 7.18 KB 0.00 KB (0.00%)
batching.ts 11.06 KB 11.06 KB 0.00 KB (0.00%)
brand.ts 6.84 KB 6.84 KB 0.00 KB (0.00%)
cache.ts 11.49 KB 11.49 KB 0.00 KB (0.00%)
config.ts 22.77 KB 22.77 KB 0.00 KB (0.00%)
differ.ts 21.92 KB 21.92 KB 0.00 KB (0.00%)
http-client.ts 26.90 KB 26.90 KB 0.00 KB (0.00%)
http-router.ts 36.88 KB 36.88 KB 0.00 KB (0.00%)
logger.ts 11.96 KB 11.96 KB 0.00 KB (0.00%)
metric.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
optic.ts 7.05 KB 7.05 KB 0.00 KB (0.00%)
pubsub.ts 15.97 KB 15.97 KB 0.00 KB (0.00%)
queue.ts 12.77 KB 12.77 KB 0.00 KB (0.00%)
schedule.ts 11.74 KB 11.74 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.02 KB 14.02 KB 0.00 KB (0.00%)
schema-binary.ts 41.06 KB 41.06 KB 0.00 KB (0.00%)
schema-class.ts 21.65 KB 21.65 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.51 KB 29.51 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.91 KB 27.91 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.27 KB 15.27 KB 0.00 KB (0.00%)
schema-string.ts 12.26 KB 12.26 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.19 KB 16.19 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.87 KB 38.87 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.10 KB 26.10 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.83 KB 20.83 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.97 KB 20.97 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.07 KB 21.07 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.11 KB 26.11 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.16 KB 21.16 KB 0.00 KB (0.00%)
schema.ts 20.75 KB 20.75 KB 0.00 KB (0.00%)
stm.ts 14.15 KB 14.15 KB 0.00 KB (0.00%)
stream.ts 10.33 KB 10.33 KB 0.00 KB (0.00%)

Comment thread .changeset/yaml-parse-result.md Resolved
@effect-bot
effect-bot changed the base branch from main to v4/next-minor October 31, 2026 08:42
@effect-janitor effect-janitor Bot removed the 4.0 label Oct 31, 2026
@tim-smart
tim-smart force-pushed the agent/bob/dc727a942ae8 branch from b4f31b5 to f5c8633 Compare October 31, 2026 08:47
@tim-smart
tim-smart merged commit 2db9fd0 into v4/next-minor Oct 31, 2026
11 checks passed
@tim-smart
tim-smart deleted the agent/bob/dc727a942ae8 branch October 31, 2026 09:02
effect-bot added a commit that referenced this pull request Nov 1, 2026
Rebased onto v4/next-minor, which already returns Result from Yaml.parse
(#10224). parseAll parses document streams with per-document anchors,
accepts %YAML 1.2, and rejects other directives and plain scalars
starting with '%'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants