Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Handle and return more errors #1268

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

MJacred
Copy link
Contributor

@MJacred MJacred commented Jul 2, 2022

PR Details

Description

Several errors are never checked against

Changes regarding error handling

  • some getter funcs now just return a pointer, there are new New*() funcs to handle initialization; full list:
    • NewCalcChainReader()
    • NewContentTypesReader()
    • NewStylesReader()
    • NewThemeReader()
    • NewWorkbookReader()
    • NOTE: they are exported for now, but can un-export them if requested
    • The reason they were separated in getters and New*() is to prevent more funcs that return errors where it's not necessary. Especially as those funcs are used pretty heavily
  • in some cases, no error was returned, because existing code already handled error -> new code in same area of said funcs respect the existing handling
  • in some cases, it seems errors should be fine, in those cases I want to at least return the first error (see firstError). And if an error occurred, handle it using continue or whatever approach fits best the respective context

new internals

  • getSheetNameBySheetXMLPath(): get worksheet name
    // by checking the sheet map against the given XML file path
    • plus its unit test
  • errors
    • ErrIncompleteFileSetup
    • ErrRangeLength
    • newRangeLengthError (for further detail on error above)

changed excels

Minor changes picked up on:

  • in NewSheet(), don't call DeleteSheet() -> not needed, because if sheet exists, it is returned
  • in OpenReader() also set: ContentTypes, WorkBook

Related Issue

closes #1267

Motivation and Context

  • fixing potential crashes
  • enable library user to react and potentially handle errors
    • currently, some funcs fail silently or could crash

How Has This Been Tested

  • running package tests locally (using golang version 1.16)

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Breaking change (fix or feature that would cause existing functionality to change)
    • because of new error returns

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
    • in code comments, add info regarding firstError returned
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • cleanup commits once everything else is fine: Sign the work, commit message lingua

Misc

Open to feedback

Benjamin Lösch added 3 commits July 2, 2022 05:35
plus
* OpenReader() now also sets: ContentTypes, WorkBook
* in NewSheet(), don't call DeleteSheet() -> not needed, because if sheet exists, it is returned
@MJacred MJacred changed the title WIP: Handle and return more errors DRAFT: Handle and return more errors Jul 2, 2022
@xuri xuri added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 2, 2022
Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

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

Thanks for your PR. This PR contains a lot of code and I need some time to review. The failure unit test case should be fixed.

@MJacred
Copy link
Contributor Author

MJacred commented Jul 5, 2022

Hi,
Yes, I'm working on the failing unit tests.

Would appreciate help with errors

  • error in sheet "Sheet2": overlapRange: invalid range length: range of "A6" is smaller than minimum range length of 2 see next comment
  • xml decode error: XML syntax error on line 1: invalid UTF-8
    • seems like the error checks were wrong, fixed with newest commit

a cell merge of once cell makes no sense
action taken: delete cell A6

Signed-off-by: Benjamin Lösch <[email protected]>
reason: overlapRange is only used by mergeOverlapCells() and putting extra error info here is more helpful for for error logging
Signed-off-by: Benjamin Lösch <[email protected]>
@MJacred
Copy link
Contributor Author

MJacred commented Jul 6, 2022

@xuri:

ok, it seems Book1.xlsx had cell A6 flagged as "merged cell". A cell merge of one cell makes no sense
Therefore, I deleted cell A6 in the excel

or was that intentional? Guessing because of this line

value, err = f.GetCellValue("Sheet2", "A6") // Merged cell ref is single coordinate.

If it was intentional, it would make sense to delete incorrect merges via code, then save corrected result.

reason: tests for "Microsoft Macintosh Excel", but app name could be anything. On linux, it could be e.g. "LibreOffice"
Signed-off-by: Benjamin Lösch <[email protected]>
@MJacred
Copy link
Contributor Author

MJacred commented Jul 6, 2022

@xuri: I'm basically finished, except if any action has to be taken because of situation stated in previous comment.
EDIT: and regarding the currently exported New*() funcs: Should I "un-export" them?

If no action is required, I'd cleanup my commits

  • add / extend func comments (aka documentation)
  • redo the commits so that all are signed

I'm thinking of doing 5 commits

  1. adding the New*() funcs
  2. new error messages + getSheetNameBySheetXMLPath() (plus its unit test)
  3. the changes this brings to all other funcs
  4. all unit tests
  5. updated Book1.xlsx

the commit message contents will be based off the current ones

@xuri xuri marked this pull request as draft July 10, 2023 01:48
@xuri xuri force-pushed the master branch 2 times, most recently from 79958aa to 0c3dfb1 Compare May 25, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Several unhandled errors
2 participants