Skip to content

Fix crash on malformed local mixin YAML#334

Merged
kindermax merged 1 commit intomasterfrom
codex/fix-malformed-mixin-yaml-crash
Apr 3, 2026
Merged

Fix crash on malformed local mixin YAML#334
kindermax merged 1 commit intomasterfrom
codex/fix-malformed-mixin-yaml-crash

Conversation

@kindermax
Copy link
Copy Markdown
Collaborator

@kindermax kindermax commented Apr 3, 2026

Summary

  • avoid dereferencing Remote when reporting mixin load errors for local mixins
  • add Mixin.Source() so error messages use the correct local file name or remote URL
  • add a regression test for malformed local mixin YAML and document the fix in the changelog

Testing

  • lets fmt
  • go test ./internal/config/...
  • go test ./...

Summary by Sourcery

Handle malformed local mixin YAML without crashing and ensure error reporting uses the correct mixin source identifier.

Bug Fixes:

  • Prevent crashes when loading malformed local mixin YAML by returning a normal parse error instead.
  • Report mixin load errors using a unified mixin source field so local mixins show their file name instead of assuming a remote URL.

Enhancements:

  • Add a Mixin source helper to abstract whether a mixin originates from a local file or remote URL.

Documentation:

  • Document the fix for malformed local mixin YAML handling in the changelog.

Tests:

  • Add a regression test verifying that malformed local mixin YAML produces the expected error messages instead of crashing.

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 3, 2026

Reviewer's Guide

Implements safer error handling when loading mixins so malformed local mixin YAML no longer crashes the loader, standardizes mixin source reporting via a new helper, adds a regression test, and documents the fix in the changelog.

Sequence diagram for mixin load error handling using Source

sequenceDiagram
    actor User
    participant App
    participant Config
    participant Mixin

    User->>App: run command with mixins
    App->>Config: readMixins(mixins)
    loop for each mixin
        Config->>Mixin: readMixin(mixin)
        Mixin-->>Config: error on malformed YAML
        alt error returned
            Config->>Mixin: Source()
            Mixin-->>Config: source string (FileName or URL)
            Config-->>App: error failed to read mixin config 'source'
        end
    end
    App-->>User: display parse error without crash
Loading

Class diagram for updated Mixin and Config mixin loading

classDiagram
    class Mixin {
        string FileName
        RemoteMixin* Remote
        UnmarshalYAML(unmarshal func_any_error) error
        IsRemote() bool
        Source() string
    }

    class RemoteMixin {
        string URL
    }

    class Config {
        readMixins(mixins []*Mixin) error
        readMixin(mixin *Mixin) error
    }

    Mixin --> RemoteMixin : has
    Config --> Mixin : reads
Loading

File-Level Changes

Change Details Files
Prevent crash when loading malformed local mixin YAML by using a unified mixin source accessor in error messages.
  • Add a Source() helper method to Mixin that returns the remote URL for remote mixins or the file name for local mixins.
  • Update readMixins to use Mixin.Source() instead of directly dereferencing mixin.Remote.URL when formatting mixin load errors.
internal/config/config/mixin.go
internal/config/config/config.go
Add regression coverage for malformed local mixin YAML and assert on the new error message shape.
  • Extend TestLoadConfig with a subtest that creates a temp project using a malformed local mixin YAML file.
  • Verify that Load returns an error and that its message includes both the high-level mixin read failure and the underlying parse error mentioning the local file name.
internal/config/load_test.go
Document the bugfix for malformed local mixin YAML in the changelog.
  • Add a Fixed entry describing that malformed local mixin YAML now yields a normal parse error instead of crashing.
docs/docs/changelog.md

Possibly linked issues

  • #bug: lets crashes when mixin is a malformed yaml: PR adds proper error handling and tests for malformed local mixin YAML, fixing the crash described.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kindermax kindermax merged commit 86bd986 into master Apr 3, 2026
5 checks passed
@kindermax kindermax deleted the codex/fix-malformed-mixin-yaml-crash branch April 3, 2026 13:14
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.

1 participant