fix(profile): improve logging for unsupported code tables#57
Merged
Conversation
Enhance the logging messages for unsupported encoding and code tables to provide clearer context. This change helps in debugging and understanding fallback behavior to Windows-1252. - Updated log messages to specify unsupported code tables - Ensured proper handling of character code table selection Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
Contributor
|
👋 Thanks for opening this PR, @adcondev! Here's what will happen next:
Please make sure:
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes code table selection logic by ensuring supported code tables are properly validated before use, and removes an unused file security helper.
- Corrects the Initialize() and SetCodeTable() functions to check for code table support before attempting to use them
- Improves error message clarity in getEncoding()
- Removes unused internal/files/files.go package
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/service/escpos_registry.go | Fixed logic in Initialize() and SetCodeTable() to properly validate code table support before selection |
| pkg/profile/escpos_encoding.go | Improved warning message clarity to explicitly mention "code table" |
| internal/files/files.go | Removed unused SafeOpen function and files package |
Comments suppressed due to low confidence (1)
pkg/service/escpos_registry.go:229
- When the code table is unsupported and falls back to WPC1252 (line 218), the profile is still updated with the original unsupported
codeTablevalue. This creates an inconsistency wherep.Profile.CodeTabledoesn't reflect the actually selected code table. Consider updating this line to:p.Profile.CodeTable = character.WPC1252when falling back, or tracking the actual selected table in a separate variable.
p.Profile.CodeTable = codeTable
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhance the logging messages for unsupported encoding and code tables to provide clearer context. This change helps in debugging and understanding fallback behavior to Windows-1252.
Descripción
Tipo de cambio
¿Cómo se ha probado?
Checklist
Notas adicionales
This pull request primarily improves the handling of character code tables in the ESC/POS printer service, ensuring unsupported code tables gracefully fall back to Windows-1252 and enhancing warning messages. Additionally, it removes an unused and potentially unsafe file handling utility.
Code table handling improvements:
InitializeandSetCodeTablemethods inpkg/service/escpos_registry.goto check if a code table is supported before selecting it, and to explicitly fall back to Windows-1252 with a warning if not. This ensures more robust and predictable printer initialization and configuration. [1] [2]EncodeStringinpkg/profile/escpos_encoding.goto clarify when an unsupported code table is encountered.Code cleanup and security:
SafeOpenfunction and related code frominternal/files/files.go, eliminating unused and potentially insecure file handling logic.