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.

matt-aitken and others added 30 commits April 8, 2022 11:55
commit 09bed34
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 8 14:03:50 2022 +0100

    Fixed the layout of a search list item

commit 90126d4
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 17:25:13 2022 +0100

    Insanely complicated path search results highlighitng and truncating

commit a4bbd55
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 14:05:01 2022 +0100

    Improved the title editing in the header

commit 5814053
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 13:38:33 2022 +0100

    Improved text highlight colour

commit 110de37
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 13:36:57 2022 +0100

    Icon hover state now uses isHighlighted

commit fb6da94
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 13:31:11 2022 +0100

    Light mode styling

commit 2c378d5
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 12:24:43 2022 +0100

    Spacing between search items no longer a hack

commit 85d90bb
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 12:19:10 2022 +0100

    Added ellipsis to search matches if they are windowed

commit 91f3e70
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 12:08:00 2022 +0100

    Fixed search item icons

commit e384c87
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 11:52:58 2022 +0100

    Improved hover state

commit f4681ed
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 11:47:33 2022 +0100

    Removed focus state on button

commit faa2d06
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 11:26:42 2022 +0100

    made the search palette a little bigger

commit df8bd52
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 11:26:14 2022 +0100

    Remove onOverlayClick prop

commit ecd046b
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 11:18:46 2022 +0100

    Close search when the overlay is clicked

commit fba330b
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 11:10:35 2022 +0100

    hitting esc when search input is focused and empty should close the search

commit fc2fe8a
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 11:00:08 2022 +0100

    Highlight the window of the best search match in the search results

commit 45193ec
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 10:45:01 2022 +0100

    Now you can arrow down to the last item in the list

commit 0de5fef
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Apr 1 10:37:20 2022 +0100

    Added a hacky margin between items and remove the transition to make it feel snappier

commit 167b548
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Apr 1 09:30:33 2022 +0100

    WIP implementing search

commit 5655631
Author: James Ritchie <james@jamesritchie.co.uk>
Date:   Fri Mar 25 15:28:19 2022 +0000

    Build and styled search modal

commit e368db8
Author: Eric Allam <eallam@icloud.com>
Date:   Fri Mar 25 14:42:03 2022 +0000

    Implement JSON search through fuse.js + web worker + react hook

commit 8caa11b
Author: Eric Allam <eallam@icloud.com>
Date:   Wed Mar 23 10:21:33 2022 +0000

    Start of the Command Palette using radix-ui Dialog

commit 904b64d
Author: Eric Allam <eallam@icloud.com>
Date:   Wed Mar 23 09:58:52 2022 +0000

    Uncommented out the search bar field
…escription, and fix the issue where the label wasn’t showing when there was no label match
Convert search from Fuse.js to @jsonhero/fuzzy-json-search
D-K-P and others added 25 commits May 3, 2023 18:13
* Replace peekalink with OpenGraph Ninja API

* Switch to url.href for OpenGraph call
* Load URI preview based on network state

* Handle URL preview endpoint failures

* Inline response

* Formats code

* Improve performance

* Improve code
Co-authored-by: = <rahulkumar@metafic.co>
fix: 🐛 handle the array use case first in the stableJson util
feat: use random user agent header when fetching JSON url's
Stop sending events go graphJSON
- 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