Skip to content

Conversation

@amikofalvy
Copy link
Collaborator

Summary

Fixes error object serialization in the CLI push command. When the API returns error objects, they were being stringified as "[object Object]" instead of showing the actual error details.

Changes

  • Added serializeErrorResponse() helper function to both projectFullClient.ts and graphFullClient.ts
  • Properly serialize error objects to human-readable strings
  • Handle errors with code + message fields (format: "code: message")
  • Fall back to JSON.stringify() for complex error objects
  • Add rawError field to structured logs for better debugging
  • Support both errorJson.error and errorJson.message response formats

Before

error: "[object Object]"

After

error: "internal_server_error: Failed query: select \"tenant_id\", \"id\", \"name\"..."

Testing

  • ✅ Verified lint passes
  • ✅ Verified build succeeds
  • ✅ Manually tested with pnpm build --filter @inkeep/agents-sdk

Links


🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

When API returns error objects, they were being stringified as "[object Object]"
instead of showing the actual error details.

Changes:
- Add serializeErrorResponse() helper function to both projectFullClient.ts and graphFullClient.ts
- Properly serialize error objects to human-readable strings
- Handle errors with code + message fields (format: "code: message")
- Fall back to JSON.stringify() for complex error objects
- Add rawError field to structured logs for better debugging
- Support both errorJson.error and errorJson.message response formats

Fixes: https://linear.app/inkeep/issue/PRD-5048/better-errors-on-push-conflicts-no-error-object-object-cli

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@changeset-bot
Copy link

changeset-bot bot commented Oct 10, 2025

⚠️ No Changeset found

Latest commit: 48f7fba

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
agents-manage-api Ready Ready Preview Comment Oct 10, 2025 6:16pm
agents-manage-ui Ready Ready Preview Comment Oct 10, 2025 6:16pm
agents-run-api Ready Ready Preview Comment Oct 10, 2025 6:16pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
agents-docs Skipped Skipped Oct 10, 2025 6:16pm

@claude
Copy link

claude bot commented Oct 10, 2025

Claude finished @amikofalvy's task —— View job


Code Review Complete

I've reviewed the error object serialization improvements in the CLI push command. Overall, this is a solid fix that addresses a real UX issue, but there are several architectural concerns and opportunities for improvement.

Review Tasks:

  • Read and analyze both modified files
  • Check for code duplication and potential abstractions
  • Review error handling patterns and consistency
  • Evaluate implementation completeness and edge cases
  • Consider system-wide architectural implications
  • Provide actionable feedback and recommendations

🚨 Critical Issues

1. Code Duplication (High Priority)

The serializeErrorResponse function is identically duplicated in both files (graphFullClient.ts:14-28 and projectFullClient.ts:13-28). This violates DRY principles and creates maintenance overhead.

Recommended Solution:

  • Move serializeErrorResponse to /packages/agents-core/src/utils/error.ts alongside existing error utilities
  • Export it and import in both client files
  • This leverages the existing error handling infrastructure
// In error.ts
export function serializeErrorResponse(error: any): string {
  if (typeof error === 'string') {
    return error;
  }

  if (typeof error === 'object' && error !== null) {
    // If error has code and message, format them nicely
    if (error.code && error.message) {
      return `${error.code}: ${error.message}`;
    }
    // Otherwise, stringify the whole object
    return JSON.stringify(error, null, 2);
  }

  return String(error);
}

2. Inconsistent Fetch Usage (Medium Priority)

  • projectFullClient.ts uses apiFetch() consistently
  • graphFullClient.ts uses native fetch() directly

This creates inconsistency in header handling and error behavior. Both should use apiFetch for consistency.

🔍 Architecture & Design Concerns

3. Redundant Error Parsing Logic (Medium Priority)

Lines 77-83 in graphFullClient.ts and 94-100 in projectFullClient.ts parse the error JSON twice:

  1. First for errorMessage generation
  2. Again for rawError logging field

Suggested Optimization:

const errorText = await response.text();
let errorMessage = `Failed to create project: ${response.status} ${response.statusText}`;
let parsedError: any;

try {
  parsedError = JSON.parse(errorText);
  const errorObject = parsedError.error || parsedError.message || parsedError;
  errorMessage = serializeErrorResponse(errorObject);
} catch {
  if (errorText) {
    errorMessage = errorText;
  }
  parsedError = errorText;
}

4. Missing Edge Case Handling (Low Priority)

Current logic checks error.code && error.message, but doesn't handle:

  • Objects with only code or only message
  • Nested error structures
  • Arrays of errors

Consider enhancing the serialization logic:

if (error.code || error.message) {
  return [error.code, error.message].filter(Boolean).join(': ');
}

5. API Response Format Inconsistency (Low Priority)

The code handles both errorJson.error and errorJson.message formats, suggesting the API returns inconsistent error structures. While this defensive handling is good, it may indicate upstream API inconsistencies worth addressing.

✅ Positive Aspects

  1. Problem Solved: Effectively addresses the "[object Object]" display issue
  2. Comprehensive Coverage: Applied to all HTTP methods (GET, POST, PUT, DELETE)
  3. Defensive Programming: Handles multiple JSON error formats gracefully
  4. Enhanced Debugging: rawError field provides valuable debugging context
  5. Backward Compatibility: Maintains existing error handling flow

📝 Additional Recommendations

6. Type Safety Enhancement

Consider creating a proper type for expected error responses:

interface ApiErrorResponse {
  error?: {
    code: string;
    message: string;
  };
  message?: string;
  // other potential fields
}

7. Consistency with Existing Error Standards

The codebase has a sophisticated error handling system in /packages/agents-core/src/utils/error.ts with RFC 7807 Problem Details format. Consider whether the serialization should align with these standards for consistency.

8. Missing Changeset

As noted by changeset-bot, this change affects the @inkeep/agents-sdk package and should include a changeset for proper versioning.

🎯 Priority Action Items

  1. Extract shared utility (addresses code duplication)
  2. Standardize fetch usage (use apiFetch in both files)
  3. Optimize error parsing logic (eliminate redundant JSON.parse calls)
  4. Add changeset for proper release management

Changed serializeErrorResponse to always use JSON.stringify for objects,
ensuring no error details are lost. Previously, errors with code+message
fields would only show those two fields, potentially hiding other important
error information.
@amikofalvy
Copy link
Collaborator Author

Updated to remove any truncation - the error serializer now always uses JSON.stringify() for objects to ensure the complete error is shown without losing any details.

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.

2 participants