-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Error handling #73
base: master
Are you sure you want to change the base?
Error handling #73
Conversation
- Add methods for VTodo and VJournal - Changed the shared properties to be attached to the ComponentBase so those methods don't need to be repeated across all attributes that share them - If a property is shared across some, but not all components, then it's a private method on the ComponentBase and public method on the Components (eg LOCATION for Event and Todo but not Journal) - Shifted position of some Event methods in the file to live after the VEvent struct
- Add methods for Alarm, Timezone, and FreeBusy - Only methods for creating and adding right now, will add methods for the properties unique to them later
- Recursive call for Alarms - SetGeo was not a public method - Missing comma in struct creation
Thanks @ManoloTonto1 I think I might make some edits to this. (When I get a bit more time.) I'm thinking along the lines of:
I do like the initiative, and that you have put it in one file, and made it more consistent. You have also kept it lower case and removed the word |
Great ideas. If I get a chance this week I can edit my pr and do some of the things you pointed out. 💯 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As pre previous comment
@ManoloTonto1 I found some time to make some changes, can you let me know what you think. I have put them as a PR into your PR: (well to your master branch:) ManoloTonto1#1 |
Also turns out there was an error in this one. The |
Seems my change pushes the requirement up to go 1.20. I will have to tag the current version before merging. |
Ok goos I will give it a look when I get some time, i am currently on a holiday with my family. As soon as I get the chance to review i will let you know. 😋 |
Bumps gopkg.in/yaml.v3 from 3.0.0-20210107192922-496545a6307b to 3.0.0. --- updated-dependencies: - dependency-name: gopkg.in/yaml.v3 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]>
…in/yaml.v3-3.0.0 Bump gopkg.in/yaml.v3 from 3.0.0-20210107192922-496545a6307b to 3.0.0
@arran4 Hey, I just got some time to work on this in the weekend. I will get back to you after I get these issues resolved. |
Sure, let me know if you have any questions or issues. |
Add VEvent.GetDtStampTime
add possibility to remove VEvent from calendar by id
Add ComponentPropertyPriority; the VTODO component can have that
hey @arran4 I fixed the merge conflicts, is there anything else that should be done before this is merged? |
errors.go
Outdated
MalformedCalendarVCalendarNotWhereExpectedError = "malformed calendar; vcalendar not where expected" | ||
|
||
StartOrEndNotYetDefinedError = "start or end not yet defined" | ||
PropertyNotFoundError = "property not found" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to be reliably compared these should be errors rather than strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(But technically not a blocker.)
errors.go
Outdated
MalformedCalendarExpectedVCalendarError = "malformed calendar; expected a vcalendar" | ||
MalformedCalendarExpectedBeginError = "malformed calendar; expected begin" | ||
MalformedCalendarExpectedEndError = "malformed calendar; expected a end" | ||
MalformedCalendarExpectedBeginOrEndError = "malformed calendar; expected begin or end" | ||
|
||
MalformedCalendarUnexpectedEndError = "malformed calendar; unexpected end" | ||
MalformedCalendarBadStateError = "malformed calendar; bad state" | ||
MalformedCalendarVCalendarNotWhereExpectedError = "malformed calendar; vcalendar not where expected" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case and others I think there there are too many errors. I would prefer to see something like:
ErrorMalformedCalendar = errors.New("malformed calendar")
Then it be embellished with detail when it is returned like @arran4 suggested in #98:
return nil, fmt.Errorf("%w: expected begin or end", ErrorMalformedCalendar)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not bothered by the quantity, but I do think regardless, it should be wrapped in a ErrorMalformedCalendar
that is a good suggestion either direction.
I have some things to do I will have to get back to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also not a blocker.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quantity has practical concerns for me: Say I'm writing a server and choosing a HTTP status code. If the user uploaded an invalid calendar I want to return 400. If something else happened, such as the connection dropped and the io.Reader returned an EOF, then I want to return 500. I now have to check if the error was any one of the many parse errors and hope that this module doesn't make any new ones. I'm happy to drop this thread but want to point out that once you ship all theses errors, you can't take it back without a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is possible using error.Is
sorry I didn't ignore this concern I just failed to follow up on it. I am happy to work through a simple example if you like?
Running tests and lint. |
Lint still fails, I think we had to bump up the go version, that seems acceptable now given how old the version we are using is. I would like to hear from people using a go version older than something released in the last 4-5 years. |
.github/workflows/test.yml
Outdated
strategy: | ||
matrix: | ||
go-version: [1.14.x, 1.15.x, 1.16.x, 1.17.x] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
go-version: ['1.14.15', '1.15.15', '1.16.15', '1.17.13', '1.22.3'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for the preference for concrete versions here?
@@ -1 +1,2 @@ | |||
/.idea/ | |||
/testdata/serialization/actual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM it's there are a couple minor issues with error wrapping. - I suggest they get fixed but I can accept that in another PR to get this one across the board.
No major blockers. (Barring lint issues.)
Let me know what you want to do.
property.go
Outdated
@@ -174,7 +234,7 @@ func ParseProperty(contentLine ContentLine) (*BaseProperty, error) { | |||
t := r.IANAToken | |||
r, np, err = parsePropertyParam(r, string(contentLine), p+1) | |||
if err != nil { | |||
return nil, fmt.Errorf("parsing property %s: %w", t, err) | |||
return nil, fmt.Errorf("%s %s: %w", ParsingPropertyError, t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't be able to catch ParsingPropertyError
error.Is
and error.As
now support multiple errors, so we can use %w
twice, past a certain go version... Since 1.20: https://www.reddit.com/r/golang/comments/z870te/multiple_error_wrapping_is_coming_in_go_120/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this technical is a bug
property.go
Outdated
switch rune(contentLine[p]) { | ||
case '=': | ||
p += 1 | ||
default: | ||
return nil, p, fmt.Errorf("missing property value for %s in %s", k, r.IANAToken) | ||
return nil, p, fmt.Errorf("%s for %s in %s", MissingPropertyValueError, k, r.IANAToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the other one. Multiple %w
are supported as of 1.20..
I guess that means we should push the go.mod up to that. -- Based on this I'm in support. 1.20 is less than 2 years old. But most stacks are rather current.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this one is just missing a %w
wish github had the same feature gitlab does "suggest a fix"
property.go
Outdated
@@ -253,11 +319,14 @@ func parsePropertyParamValue(s string, p int) (string, int, error) { | |||
for ; p < len(s) && !done; p++ { | |||
switch s[p] { | |||
case 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08: | |||
return "", 0, fmt.Errorf("unexpected char ascii:%d in property param value", s[p]) | |||
return "", 0, fmt.Errorf("%s:%d in property param value", UnexpectedASCIICharError, s[p]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%w
The merge-base changed after approval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As before -- The approval expired for some reason.
property.go
Outdated
switch rune(contentLine[p]) { | ||
case '=': | ||
p += 1 | ||
default: | ||
return nil, p, fmt.Errorf("missing property value for %s in %s", k, r.IANAToken) | ||
return nil, p, fmt.Errorf("%s for %s in %s", MissingPropertyValueError, k, r.IANAToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this one is just missing a %w
wish github had the same feature gitlab does "suggest a fix"
The merge-base changed after approval.
Let me fix the lint issues, then we can merge. Maybe we can tackle the other issue some other time. |
OK |
Conflicting files
Which is:
|
@ManoloTonto1 I have fixed the conflicts in the PR into your PR: ManoloTonto1#1 Once you merge that in this should work then I can.... review it again. I fixed the issues without looking at anything else sorry. It's also possible that the PR I created earlier doesn't actually resolve some of your issues. However I would encourage you to merge it into your PR. I can also create a new PR here and then merge it myself, I will retain your commits if I do. |
* Add leaks and vunerability checks * Requires secrets now * Renamed interface as it's useful own it's own. Made it public. Added a comment * Some suggestions, this could be improved still. * Version bump required by this change. * 19 too fails. * Should be able to distinguish unset from invalid time properties * Improve error for property not found Co-authored-by: Arran Ubels <[email protected]> * Remove deprecated ioutil * Move targeted Go version to 1.20 And test the target forever * Add method to remove property Fixes arran4#95 * Merged * New tool * Test fixed. * Fixed test failure. (Error wrapping needed to be considered in EOF checks.) * %s => %w fixes and an additional error. --------- Co-authored-by: Bracken Dawson <[email protected]> Co-authored-by: Daniel Lublin <[email protected]>
Cool. Now to sort though the new conflicts. |
Tried to resolve conflicts in: ManoloTonto1#2 If preferable I can run with this entirely in: #109 your commits will still show up in the code base. I'm going to give this PR until the end of the month then make a decision on my own. |
* Add leaks and vunerability checks * Requires secrets now * Renamed interface as it's useful own it's own. Made it public. Added a comment * fix: omit zone in "AllDay" event helpers For a date-only event (i.e., an event that lasts for the full day) the iCalendar specification indicates that the value for DTSTART / DTEND should be a DATE https://icalendar.org/iCalendar-RFC-5545/3-6-1-event-component.html > The "VEVENT" is also the calendar component used to specify an > anniversary or daily reminder within a calendar. These events have a > DATE value type for the "DTSTART" property instead of the default value > type of DATE-TIME. If such a "VEVENT" has a "DTEND" property, it MUST be > specified as a DATE value also The DATE format (https://icalendar.org/iCalendar-RFC-5545/3-3-4-date.html) should omit both time and zone/location elements and additionally notes that "The "TZID" property parameter MUST NOT be applied to DATE properties" As per the specification, this PR also adds an explicit "VALUE=DATE" parameter when the AllDay helpers were called, to indicate that the property's default value type has been overridden and the VEVENT is intended to be an all-day event https://icalendar.org/iCalendar-RFC-5545/3-2-20-value-data-types.html Finally the SetDuration call has been updated to preserve the "AllDay" characteristics if the existing start or end has been specified in DATE format, which is also a requirement of the spec. Contributes-to: arran4#55 * calendar parsing url support * usage example, README * added functionnal option pattern for url parsing * Should be able to distinguish unset from invalid time properties * Improve error for property not found Co-authored-by: Arran Ubels <[email protected]> * Remove deprecated ioutil * Move targeted Go version to 1.20 And test the target forever * Add method to remove property Fixes arran4#95 * Merged * New tool * Reintegration of arran4#67 * Resynced and moved some functions around arran4#78 * Test fixed. * Create bug.md * Create other.md * Create default.md * Rename default.md to pull_request_template.md * Minor update * refactor: remove unnecessary named return values, harmonizing code base * refactor: rename var to reflect what it is These functions take optional variadic PropertyParam arguments, in ical speak they are not properties, but parameters for a property. * refactor: use ReplaceAll * refactor: prefer switch for readability * refactor: use consistent receiver names * refactor: rename unused arg as '_' * Tests added. * Some larger upgrades. * Fix * Some multiple-ness. * Duplication issue fixed. * Merged * Merge remote-tracking branch 'origin/master' into issue97 * origin/master: Duplication issue fixed. Some multiple-ness. Test fixed. Resynced and moved some functions around arran4#78 added functionnal option pattern for url parsing usage example, README calendar parsing url support # Conflicts: # calendar.go # calendar_test.go # components.go --------- Co-authored-by: Dominic Evans <[email protected]> Co-authored-by: tradulescu <[email protected]> Co-authored-by: Bracken Dawson <[email protected]> Co-authored-by: Daniel Lublin <[email protected]>
Turns out my PR wasn't enough, there are still more conflicts. -_- |
Let me resolve them now, I will get back to you |
Thanks. We can also switch to: #109 which I believe I have solved them. I suspect that the conflicts remaining are due to the way github tracks merge history -- I suspect it ignores merges. |
This pr contains all errors in a file called
errors.go
for better error handling for the end-user.closes #71
all tests a passing.