Skip to content

Conversation

ArjunCodess
Copy link

@ArjunCodess ArjunCodess commented Oct 1, 2025

fixes #186 and #182 by improving file size handling and error notifications.

Changes

File size handling

  • Increase limit from 1MB to 5MB (maxSize: 1024 * 1024 * 5)
  • Add onDropRejected with clear error messages
  • Show actual file size vs. limit
  • Display "Maximum file size: 5MB" in the UI

Error handling

  • Client-side JSON validation before submission
  • Server-side error handling with toast notifications
  • Visual error indicators with warning icons
  • Clear, actionable error messages

User experience

  • Immediate feedback on file rejection
  • Visual error styling with red borders and warning icons
  • Better error recovery with guidance
  • Consistent error handling across client and server

Technical details

Client-side (DragAndDropForm.tsx)

// File rejection handling
const onDropRejected = useCallback((fileRejections: any[]) => {
  const rejection = fileRejections[0];
  if (rejection?.errors?.[0]?.code === 'file-too-large') {
    setErrorMessage(`File is too large. Maximum size is 5MB. Your file is ${(rejection.file.size / (1024 * 1024)).toFixed(2)}MB.`);
  }
  // ... other error handling
}, []);

// Client-side JSON validation
try {
  JSON.parse(jsonValue);
  rawJsonInputRef.current.value = jsonValue;
  submit(formRef.current);
} catch (error) {
  const errorMsg = error instanceof Error ? error.message : "Invalid JSON format";
  setErrorMessage(`JSON parsing error: ${errorMsg}`);
}

Server-side (createFromFile.ts)

// Comprehensive error handling
try {
  const doc = await createFromRawJson(filename, rawJson);
  return redirect(`/j/${doc.id}`);
} catch (error) {
  if (error instanceof Error) {
    if (error.message.includes("JSON")) {
      setErrorMessage(toastCookie, "Invalid JSON format", "The file contains invalid JSON...");
    } else if (error.message.includes("too large")) {
      setErrorMessage(toastCookie, "File too large", "The JSON file is too large to process...");
    }
    // ... more error handling
  }
}

JSON validation (jsonDoc.server.ts)

// Enhanced JSON validation with better error messages
try {
  JSON.parse(contents);
} catch (error) {
  const errorMessage = error instanceof Error ? error.message : "Invalid JSON format";
  throw new Error(`JSON parsing failed: ${errorMessage}`);
}

Issues resolved

Issue #186: "Notify if file is too big"

  • Users get immediate feedback when files exceed the size limit
  • Clear error messages show actual file size vs. limit
  • Visual indicators with warning icons
  • Real-time feedback when files are rejected

Issue #182: "Local JSON Hero failing on 25K line file"

  • Increased file size limit from 1MB to 5MB
  • Better error handling for large files
  • Improved JSON parsing error messages
  • Handles 25K+ line files

Testing

  • File size validation with files over 5MB
  • JSON parsing error handling with invalid JSON
  • Visual error indicators display correctly
  • Toast notifications work for server-side errors
  • File size information displays correctly
  • No linting errors introduced

Screenshots

image

Before

  • No feedback when files are too large
  • Silent failures for invalid JSON
  • 1MB file size limit

After

  • Clear error messages with file size information
  • Visual error indicators with warning icons
  • 5MB file size limit with user-friendly notifications

Breaking changes

None.

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • Comments added for complex logic
  • Documentation updated (if needed)
  • No new warnings introduced
  • Changes are backward compatible

Related issues

Additional notes

This improves the experience for large JSON files while maintaining performance and reliability. Users get clear, actionable feedback when encountering file size or JSON parsing issues.

- Add try-catch block to handle JSON parsing errors in createFromRawJson function
- Improve error messages for invalid JSON format during parsing and validation
- Ensure consistent error handling across JSON operations
- Add try-catch block to handle errors during JSON file processing
- Implement specific error messages for invalid JSON format and file size issues
- Set error messages in toast notifications for user feedback
- Redirect to home with updated session cookie on error
- Add error messages for file reading issues and invalid JSON format
- Implement specific feedback for file size and type rejections
- Update maximum file size limit to 5MB
- Display error messages to users in the UI for better feedback
@ArjunCodess
Copy link
Author

@matt-aitken hey! :)

if there is anything left to implement / anything to be edited, please let me know!

@ArjunCodess
Copy link
Author

@matt-aitken just a follow-up.

1 similar comment
@ArjunCodess
Copy link
Author

@matt-aitken just a follow-up.

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.

Notify if file is too big Local JSON Hero failing on 25K line file
1 participant