Skip to content

Fix empty egg config_files causing fatal 500 error (#2195)#2197

Merged
lancepioch merged 2 commits intomainfrom
lance/2195
Feb 12, 2026
Merged

Fix empty egg config_files causing fatal 500 error (#2195)#2197
lancepioch merged 2 commits intomainfrom
lance/2195

Conversation

@lancepioch
Copy link
Copy Markdown
Member

When the Configuration Files field on an egg is cleared and saved, json_decode returns null which crashes the server creation/startup flow with a TypeError. Handle null/empty config_files gracefully at the service and transformer level, and add a default to the edit form to match the create form.

Fixes #2195

When the Configuration Files field on an egg is cleared and saved,
json_decode returns null which crashes the server creation/startup
flow with a TypeError. Handle null/empty config_files gracefully
at the service and transformer level, and add a default to the
edit form to match the create form.
@lancepioch lancepioch self-assigned this Feb 8, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

Defaults and type guards for egg configuration fields were added across the admin UI, API transformer, and service layer so empty or null configuration fields are treated as an empty JSON object and validated before processing.

Changes

Cohort / File(s) Summary
Admin UI
app/Filament/Admin/Resources/Eggs/Pages/EditEgg.php
Textarea for Process Management configuration_files now dehydrates empty state to '{}', ensuring the field serializes as a JSON object when blank.
Backend: Transformer & Service
app/Transformers/Api/Application/EggTransformer.php, app/Services/Eggs/EggConfigurationService.php
Transformer defaults certain JSON fields (inherit_config_files, startup, logs) to '{}' before json_decode. Service decodes inherit_config_files with fallback to '{}' and validates result is array/object before calling replacePlaceholders to avoid processing non-container values.

Sequence Diagram(s)

sequenceDiagram
    participant AdminUI as Admin UI (EditEgg)
    participant API as API Transformer
    participant Service as EggConfigurationService
    participant Processor as replacePlaceholders

    AdminUI->>API: Submit egg data (config_files may be blank)
    API->>API: Coerce null/empty -> '{}' and json_decode fields
    API->>Service: Pass transformed payload (inherit_config_files decoded)
    Service->>Service: json_decode with fallback '{}', validate is array/object
    alt decoded is array/object
        Service->>Processor: call replacePlaceholders(with decoded config)
        Processor-->>Service: return processed configs
    else not container
        Service->>Service: use empty array for configs
    end
    Service-->>API: return processed configuration/result
    API-->>AdminUI: respond with success
Loading

Possibly related PRs

  • fix eggs with [] #1596: Changes to replacePlaceholders handling and its accepted input types, directly related to the type-validation and fallback logic added in EggConfigurationService.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing empty config_files causing fatal 500 errors, with the issue reference.
Description check ✅ Passed The description is directly related to the changeset, explaining the null handling approach and form default addition to fix the crash issue.
Linked Issues check ✅ Passed The PR implements graceful null/empty handling in service and transformer layers, preventing 500 errors during server creation/startup as required by #2195.
Out of Scope Changes check ✅ Passed All three modified files directly address the issue: form default, service-level null handling, and API transformer null safety for config_files and related fields.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
app/Filament/Admin/Resources/Eggs/Pages/EditEgg.php (1)

316-325: Consider applying the same dehydrateStateUsing guard to config_startup and config_logs.

Both config_startup (line 316) and config_logs (line 323) are similarly JSON-decoded downstream. While the transformer now guards against empty strings with ?:, applying the same dehydration default here would keep the form-level defense consistent across all three fields.

♻️ Suggested diff
-                    Textarea::make('config_startup')->rows(10)->json()
+                    Textarea::make('config_startup')->rows(10)->json()
                         ->label(trans('admin/egg.start_config'))
+                        ->dehydrateStateUsing(fn ($state) => blank($state) ? '{}' : $state)
                         ->helperText(trans('admin/egg.start_config_help')),
                     Textarea::make('config_files')->rows(10)->json()
                         ->label(trans('admin/egg.config_files'))
                         ->dehydrateStateUsing(fn ($state) => blank($state) ? '{}' : $state)
                         ->helperText(trans('admin/egg.config_files_help')),
-                    Textarea::make('config_logs')->rows(10)->json()
+                    Textarea::make('config_logs')->rows(10)->json()
                         ->label(trans('admin/egg.log_config'))
+                        ->dehydrateStateUsing(fn ($state) => blank($state) ? '{}' : $state)
                         ->helperText(trans('admin/egg.log_config_help')),

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/Transformers/Api/Application/EggTransformer.php (1)

54-58: ⚠️ Potential issue | 🟠 Major

Apply null-safety pattern consistently to all config JSON fields.

inherit_config_startup (line 56) and inherit_config_logs (line 58) are decoded without null guards, but inherit_config_files (line 39) uses the pattern ?? '{}' to provide a safe default. Since all three fields are nullable, apply the same pattern to maintain consistency:

'startup' => json_decode($model->inherit_config_startup ?? '{}', true),
'logs' => json_decode($model->inherit_config_logs ?? '{}', true),
🤖 Fix all issues with AI agents
In `@app/Filament/Admin/Resources/Eggs/Pages/EditEgg.php`:
- Around line 319-322: The Textarea field Textarea::make('config_files') in
EditEgg.php uses ->default('{}') which doesn't affect records on the EditRecord
page because existing state is hydrated from the DB; to ensure empty submissions
are saved as '{}' instead of null/empty, add a dehydration coercion on that
field such as ->dehydrateStateUsing(fn($state) => blank($state) ? '{}' : $state)
or mark it ->nullable() and implement a mutator to replace blank values with
'{}' before save; keep downstream guards in EggConfigurationService and
EggTransformer but ensure the field-level dehydrate/mutator fixes empty-save
behavior.

In `@app/Transformers/Api/Application/EggTransformer.php`:
- Line 39: The json_decode call for $files uses the null-coalescing operator
(??) which doesn't guard against empty strings and will still throw
JsonException for ''. Update the fallback so that inherit_config_files is
treated as falsy (empty string included) before decoding—i.e., use a
falsy-coalescing approach so json_decode receives '{}' when
$model->inherit_config_files is null or ''. Locate the json_decode(...) line
that references $model->inherit_config_files and replace the ?? fallback with a
falsy fallback (so decoding gets '{}' when the stored value is null/empty) while
keeping JSON_THROW_ON_ERROR.

Comment thread app/Filament/Admin/Resources/Eggs/Pages/EditEgg.php
Comment thread app/Transformers/Api/Application/EggTransformer.php Outdated
- Use ?: instead of ?? in EggTransformer so empty strings also fall back to '{}'
- Apply same null-safety to config_startup and config_logs json_decode calls
- Replace ineffective default('{}') with dehydrateStateUsing on EditEgg form
@lancepioch lancepioch merged commit d43cb1d into main Feb 12, 2026
32 checks passed
@lancepioch lancepioch deleted the lance/2195 branch February 12, 2026 22:06
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty Egg Configuration Silently Causes Fatal Error

1 participant