Skip to content

fix(farm): pass string messages to Farm warn and error context - #648

Open
willnie9 wants to merge 1 commit into
unjs:mainfrom
willnie9:fix/farm-context-string-message
Open

willnie9 wants to merge 1 commit into
unjs:mainfrom
willnie9:fix/farm-context-string-message

Conversation

@willnie9

@willnie9 willnie9 commented Nov 23, 2026 •

Copy link
Copy Markdown

Closes #647

Summary

  • Normalize this.warn() and this.error() arguments to a string in unpluginContext (src/farm/context.ts) before forwarding to Farm's CompilationContext.warn / CompilationContext.error.
  • Farm's native binding expects a string argument and panics (SIGABRT) when passed an Error or non-string object.
  • Updated unit tests in test/unit-tests/farm/context.test.ts covering string, Error, and { message } inputs for both warn and error.

Verification

  • pnpm build
  • pnpm typecheck
  • pnpm lint
  • pnpm vitest run test/unit-tests/farm (3 files, 50/50 tests passed)

Summary by CodeRabbit

  • Bug Fixes
    • Error and warning messages are now consistently provided as readable text. Existing string messages remain unchanged, while errors and objects with a message display that message. Other values are converted to text, helping ensure diagnostic details are available in a consistent format.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 03:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Farm adapter now converts warning and error inputs to strings before forwarding them to the compilation context. It preserves string inputs, uses messages from errors and objects with string messages, and converts other values with String.

Changes: Farm context message forwarding

Layer / File(s) Summary
Format and forward messages
src/farm/context.ts, test/unit-tests/farm/context.test.ts
The adapter formats warning and error inputs as strings before forwarding them. Tests cover string inputs, Error instances, and objects with string messages.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: antfu, ysknsid25

Merge Risk: Minimal · up to 5cbff

This change makes Farm's warn and error calls pass string messages, which avoids the reported native abort. The change is small, tests cover the main input shapes, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the Farm adapter fix: string messages are now passed to the Farm warn and error context. The change normalizes this.warn() and this.error() arguments to strings in unpluginContext, and…
Linked Issues check Passed Issue #647 requires that this.warn and this.error pass messages to Farm as strings, so that Farm does not panic for string, Error, or { message } arguments. At the reviewed head, `src/farm/con…
Out of Scope Changes check Passed The PR changes src/farm/context.ts (message normalization in unpluginContext) and test/unit-tests/farm/context.test.ts (tests for the new behavior). Both changes directly implement the issue #64…
Full details: Title check

Explanation

The title names the Farm adapter fix: string messages are now passed to the Farm warn and error context. The change normalizes this.warn() and this.error() arguments to strings in unpluginContext, and the tests cover string, Error, and { message } inputs. The title matches the main change and is specific.

Full details: Linked Issues check

Explanation

Issue #647 requires that this.warn and this.error pass messages to Farm as strings, so that Farm does not panic for string, Error, or { message } arguments. At the reviewed head, src/farm/context.ts adds formatMessage. It returns strings unchanged, returns error.message for Error instances and for objects with a string message, and falls back to String(error). unpluginContext passes the result to context.warn and context.error, so Farm receives a string in every case. The unit tests in test/unit-tests/farm/context.test.ts cover string, Error, and { message } inputs for both methods, per the PR description. The issue expected behavior (warnings print, errors fail the build with the message) depends on Farm's native runtime. That runtime behavior was not executed in this review. The evidence from the code change and the reported unit-test results supports the requirement. The issue's resolveId enforce: 'pre' note concerns reproduction setup, not a code requirement. No non-coding requirements apply.

Full details: Out of Scope Changes check

Explanation

The PR changes src/farm/context.ts (message normalization in unpluginContext) and test/unit-tests/farm/context.test.ts (tests for the new behavior). Both changes directly implement the issue #647 objective. No unrelated changes appear in the PR summary. The whole-PR diff could not be read as text, so this verdict relies on the PR summary and the head file content. The head file contains only the Farm context changes, with no unrelated edits visible.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/farm/context.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

test/unit-tests/farm/context.test.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: faf2d312-38aa-44e2-89f0-b8a7ccb7fe54
Commits

Reviewing files that changed from the base of the PR and between 5daf6e6 and 5cbfff1.

Files selected for processing: 2

  • src/farm/context.ts
  • test/unit-tests/farm/context.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Farm adapter: this.warn and this.error abort the process

3 participants