Skip to content

fix: improve file size limit feedback with adaptive KB/MB units#312

Merged
haiphucnguyen merged 2 commits intohaiphucnguyen:mainfrom
miguel-baptista07:fix/file-size-limit-feedback-274
Apr 8, 2026
Merged

fix: improve file size limit feedback with adaptive KB/MB units#312
haiphucnguyen merged 2 commits intohaiphucnguyen:mainfrom
miguel-baptista07:fix/file-size-limit-feedback-274

Conversation

@miguel-baptista07
Copy link
Copy Markdown
Contributor

Fixes #274

Problem

The file size error message was always showing "0.0MB" for small files because the calculation always divided by 1024×1024, giving a result less than 1 for small files.

Changes

  • Added adaptive units: shows KB when file is smaller than 1MB, MB otherwise
  • Fixed secondary bug dividing by 1000×1000 instead of 1024×1024 in FileSizeExceededException
  • Applied fix in 4 locations: ChatInputField.kt, ErrorHandler.kt (×2) and FileContentExtractor.kt

Before

File 'file_teste.txt' is too large (0,0MB). Maximum allowed size is 0,0MB.

After

File 'file_teste.txt' is too large (4 KB). Maximum allowed size is 1 KB.

@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Apr 8, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ haiphucnguyen
❌ Miguelkn
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Owner

@haiphucnguyen haiphucnguyen left a comment

Choose a reason for hiding this comment

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

Hi @miguel-baptista07 , thanks for your PR.

I left some minor comments, and you could resolve the conflict of ChatSessionService then this PR is good to go

Comment thread tools/git/pre-commit Outdated
@@ -1,4 +1,4 @@
#!/bin/sh
git checkout main#!/bin/sh
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is redudant text?

// Return user-friendly message based on exception type
return when (exception) {
is FileSizeExceededException -> {
val fileSizeStr = if (exception.fileSize >= 1_048_576) "${String.format("%.1f", exception.fileSize / 1_048_576.0)} MB" else "${exception.fileSize / 1024} KB"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We should have a common method for this logic

  val fileSizeStr = if (exception.fileSize >= 1_048_576) "${String.format("%.1f", exception.fileSize / 1_048_576.0)} MB" else "${exception.fileSize / 1024} KB"
            val maxSizeStr = if (exception.maxAllowedSize >= 1_048_576) "${String.format("%.1f", exception.maxAllowedSize / 1_048_576.0)} MB" else "${exception.maxAllowedSize / 1024} KB"
            "File is too large ($fileSizeStr). Maximum allowed size is $maxSizeStr."

since it is the same with one in the class ChatInputField?

// Try to get a specific message first
val specificMessage = when (exception) {
is FileSizeExceededException -> {
val fileSizeStr = if (exception.fileSize >= 1_048_576) "${String.format("%.1f", exception.fileSize / 1_048_576.0)} MB" else "${exception.fileSize / 1024} KB"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

sane like above, a common method convert to proper MB or Kb is helpful

Copy link
Copy Markdown
Owner

@haiphucnguyen haiphucnguyen left a comment

Choose a reason for hiding this comment

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

Thanks @miguel-baptista07 for your contribution, I left some minor comments.

Also you should resolve the conflict of ChatSessionService, then this PR is good to go

@haiphucnguyen
Copy link
Copy Markdown
Owner

Screenshot 2026-04-08 at 8 56 09 AM

Also could you sign this CLA for once time. Thanks

@miguel-baptista07
Copy link
Copy Markdown
Contributor Author

image

done!

- Fix size display showing 0.0MB for small files by using adaptive units
- Show KB when file is smaller than 1MB, MB otherwise
- Fix secondary bug dividing by 1000x1000 instead of 1024x1024
- Applied fix in ChatInputField.kt, ErrorHandler.kt and FileContentExtractor.kt

Fixes haiphucnguyen#274

Signed-off-by: Miguel <miguelkevlin23@gmail.com>
@miguel-baptista07 miguel-baptista07 force-pushed the fix/file-size-limit-feedback-274 branch from d191cd7 to 47ba914 Compare April 8, 2026 16:34
@miguel-baptista07
Copy link
Copy Markdown
Contributor Author

Hi @haiphucnguyen, addressed all comments:

  • Removed redundant text from tools/git/pre-commit
  • Extracted KB/MB conversion into the existing formatFileSize utility method
  • Resolved the ChatSessionService conflict by removing unused import

Ready for review! 🙏

@haiphucnguyen
Copy link
Copy Markdown
Owner

Thank you @miguel-baptista07 ! Looking forward to your new contributions!

@haiphucnguyen haiphucnguyen merged commit 7d54c42 into haiphucnguyen:main Apr 8, 2026
15 of 17 checks passed
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.

Improve file size limit feedback

3 participants