Skip to content

fix(fs): handle folder info array response#4

Merged
xrgzs merged 1 commit into
OpenListTeam:mainfrom
syscc:fix-folder-info-path-array
Jun 2, 2026
Merged

fix(fs): handle folder info array response#4
xrgzs merged 1 commit into
OpenListTeam:mainfrom
syscc:fix-folder-info-path-array

Conversation

@syscc

@syscc syscc commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes the root cause behind OpenListTeam/OpenList#2562.

The 115 Open /open/folder/get_info API may return data as an array for path-based folder info lookups, especially when the requested path is missing. The SDK currently always unmarshals data into GetFolderInfoResp, so callers receive:

json: cannot unmarshal array into Go value of type sdk.GetFolderInfoResp

This change makes GetFolderInfoResp accept both shapes:

  • object: existing behavior
  • non-empty array: use the first item
  • empty array: return ErrObjectNotFound

This allows callers such as OpenList to distinguish missing objects from real JSON/schema failures.

Related

Testing

  • gofmt -w fs.go error.go fs_test.go
  • git diff --check

I did not run go test locally because the downstream OpenList task is under a local testing constraint that forbids generating compiled test artifacts/caches.

AI Disclosure

This PR includes AI-assisted content.

Tools used:

  • OpenAI Codex

Usage scope:

  • Code generation
  • Test drafting
  • PR description drafting

I reviewed and validated the AI-assisted content before submission. The commit includes Co-authored-by: OpenAI Codex <codex@openai.com> attribution.

Co-authored-by: OpenAI Codex <codex@openai.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes GetFolderInfo / GetFolderInfoByPath decoding when the 115 /open/folder/get_info API returns data as an array (notably for missing path lookups), enabling callers to reliably detect “not found” vs. true JSON/schema errors.

Changes:

  • Added a custom UnmarshalJSON to GetFolderInfoResp to accept both object and array data shapes, mapping an empty array to ErrObjectNotFound.
  • Introduced ErrObjectNotFound as a package-level sentinel error for missing objects.
  • Added unit tests covering object, array, and empty-array unmarshalling for GetFolderInfoResp.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
fs.go Implements tolerant JSON unmarshalling for folder info responses that may be object or array.
error.go Adds a reusable ErrObjectNotFound sentinel error.
fs_test.go Adds tests validating the new unmarshalling behavior, including the empty-array not-found case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@xrgzs xrgzs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@xrgzs xrgzs merged commit 8be4599 into OpenListTeam:main Jun 2, 2026

@SheltonZhu SheltonZhu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

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.

4 participants