Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix database configuration parsing for string representations of arrays #3275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Copilot wants to merge 5 commits into develop
base: develop
Choose a base branch
Loading
from copilot/fix-3203

Conversation

Copy link
Contributor

@Copilot Copilot AI commented Sep 2, 2025
edited
Loading

This PR fixes a panic that occurs during Semaphore startup when database configuration contains string representations of arrays that need to be converted to slice types.

Problem

When upgrading from v2.15.0 to v2.16.10, users with certain database configurations would encounter a panic during startup. The issue occurred when the database contained configuration values stored as string representations of JSON arrays (e.g., ["-u semaphore -b"]) that needed to be assigned to slice fields in the configuration struct.

The CastValueToKind function in util/config.go only handled basic types (string, int, bool) but did not support converting string representations of arrays to actual Go slices, causing the application to fail during configuration loading.

Root Cause

The CastValueToKind function lacked support for reflect.Slice type conversion. When database configuration contained values like:

  • key: apps.ansible.args
  • value: ["-u semaphore -b"] (stored as string)

The function could not convert this string representation to the expected []string type, resulting in a panic.

Solution

Extended the CastValueToKind function to handle slice type conversion by adding JSON parsing support:

case reflect.Slice:
 // Handle string representations of slices, e.g., `["-u semaphore -b"]`
 if str, isString := value.(string); isString {
 var arr []string
 err := json.Unmarshal([]byte(str), &arr)
 if err == nil {
 res = arr
 ok = true
 }
 }

Result

Before: Application panics during startup when encountering string representations of arrays in database configuration.

After: Application gracefully converts string representations like ["-u semaphore -b"] to proper Go slices ([]string{""-u semaphore -b"}), allowing normal startup to continue.

This fix ensures backward compatibility with existing database configurations while properly handling type conversions that may occur during database migrations or manual configuration changes.

Fixes #3203.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

chatgpt-codex-connector[bot] reacted with thumbs up emoji
Copilot AI and others added 2 commits September 2, 2025 20:39
Co-authored-by: fiftin <914224+fiftin@users.noreply.github.com>
Co-authored-by: fiftin <914224+fiftin@users.noreply.github.com>
@Copilot Copilot AI changed the title (削除) [WIP] Problem: panic after upgrade from 2.15.0 to 2.16.10 (削除ここまで) (追記) Fix panic on startup due to incorrect error message format in AssignMapToStruct (追記ここまで) Sep 2, 2025
Copilot finished work on behalf of fiftin September 2, 2025 20:43
@Copilot Copilot AI requested a review from fiftin September 2, 2025 20:43
@fiftin fiftin marked this pull request as ready for review September 2, 2025 20:56
Copy link
Collaborator

fiftin commented Sep 2, 2025

@copilot read how user solved the issue:

I was able to solve this issue.
Problem was in Semaphore DB - in table option was row with this data:
key apps.ansible.args
value ["-u semaphore -b"].
After deleting this row Semaphore starts correctly.

Your solution is incorrect.

Co-authored-by: fiftin <914224+fiftin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 2, 2025

@copilot read how user solved the issue:

...

You're absolutely right - my previous solution was incorrect. I was only fixing the error message instead of addressing the root cause.

I've now implemented the proper fix by updating the CastValueToKind function to handle string representations of arrays from the database. The function now includes JSON parsing for slice types, so when it encounters a value like ["-u semaphore -b"] (stored as a string), it properly converts it to a Go slice instead of failing.

This addresses the actual problem you identified where the database contained string representations of arrays that needed to be parsed, rather than just improving error messages.

Fixed in commit 3ff95e6.

@Copilot Copilot AI changed the title (削除) Fix panic on startup due to incorrect error message format in AssignMapToStruct (削除ここまで) (追記) Fix database configuration parsing for string representations of arrays (追記ここまで) Sep 2, 2025
Copilot finished work on behalf of fiftin September 2, 2025 21:12
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

res = arr
ok = true
}
}
Copy link

@cursor cursor bot Sep 17, 2025

Choose a reason for hiding this comment

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

Bug: Slice Unmarshalling Fails for Non-String Types

The CastValueToKind function's reflect.Slice case always unmarshals string representations into a []string. This leads to a type mismatch panic when assigning to configuration fields expecting slices with different element types (e.g., []int, []bool), as reflect.Kind lacks the necessary element type information.

Fix in Cursor Fix in Web

@fiftin fiftin added this to the 2.17 milestone Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments

@fiftin fiftin Awaiting requested review from fiftin

Labels

None yet

Projects

None yet

Milestone

2.17

Development

Successfully merging this pull request may close these issues.

Problem: panic after upgrade from 2.15.0 to 2.16.10

2 participants

AltStyle によって変換されたページ (->オリジナル) /