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

Unify error messages and prepare to adopt wrapping error messages, part 1 #518

Closed
wants to merge 43 commits into from

Conversation

conallob
Copy link
Contributor

@conallob conallob commented May 11, 2023

Unify error messages by using the errors module. Prepare for wrapping errors once Go v1.20 is the default.

This is part 1 of an implementation for #358

@SuperQ
Copy link
Member

SuperQ commented May 11, 2023

This needs a DCO sign-off. You can use git commit -s --amend to add it.

dependabot bot and others added 16 commits May 11, 2023 22:54
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/golang/sys/releases)
- [Commits](golang/sys@v0.6.0...v0.7.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: conall <conall@conall.net>
and MountError

Signed-off-by: conall <conall@conall.net>
…riables

- Include original err whenever raising an exception

Signed-off-by: conall <conall@conall.net>
issue was found by Svace static analyzer (https://www.ispras.ru/en/technologies/svace/)

Signed-off-by: Artem Seleznev <seleznyov.artyom@gmail.com>
Signed-off-by: conall <conall@conall.net>
Can be used by other projects (eg node_exporter) to read a single
sysfs file rather than all of them at once, which can cause
lock contention in the kernel as many sysfs net files grab the
RTNL lock.

Signed-off-by: Dan Williams <dcbw@redhat.com>
Signed-off-by: conall <conall@conall.net>
Modernised method of fetching mdraid statistics via machine-readable
sysfs entries, instead of parsing human-readable /proc/mdstat.

Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
Signed-off-by: conall <conall@conall.net>
Signed-off-by: shankeerthan-kasilingam <shankeerthan1995@gmail.com>
Signed-off-by: conall <conall@conall.net>
Signed-off-by: conall <conall@conall.net>
… and cpuinfo.go

Signed-off-by: conall <conall@conall.net>
fscache.go

Signed-off-by: conall <conall@conall.net>
Signed-off-by: conall <conall@conall.net>
Move the file hadling into the parseNetstat() function to only open one
file at a time. This eliminates keeping all files open until all are
read.

Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: conall <conall@conall.net>
mountstats.go

Signed-off-by: conall <conall@conall.net>
@conallob conallob marked this pull request as ready for review May 12, 2023 15:45
Signed-off-by: conall <conall@conall.net>
Signed-off-by: conall <conall@conall.net>
Signed-off-by: conall <conall@conall.net>
and net_ip_socket.go

Signed-off-by: conall <conall@conall.net>
fmt.Errorf() atoms when there is no err to wrap

Signed-off-by: conall <conall@conall.net>
Signed-off-by: conall <conall@conall.net>
Signed-off-by: conall <conall@conall.net>
loadavg.go Outdated Show resolved Hide resolved
mdstat.go Outdated Show resolved Hide resolved
Signed-off-by: conall <conall@conall.net>
Signed-off-by: conall <conall@conall.net>
fmt.Errorf() is only available in Go v1.20+ https://go.dev/doc/go1.20#errors

Signed-off-by: conall <conall@conall.net>
Signed-off-by: conall <conall@conall.net>
@conallob
Copy link
Contributor Author

No, I think just using some %s is fine for now. For cases where there is multi-error, prefer to pass the underlying error, not the new error type.

Done.

I've also filed #519 to track replacing these %s with %w again, once Go v1.20 is the default

fscache.go Outdated Show resolved Hide resolved
Co-authored-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Conall O'Brien <conall@conall.net>
@conallob
Copy link
Contributor Author

Opened #520 to try and fix up golangci-lint

Signed-off-by: Conall O'Brien <conall@conall.net>
Signed-off-by: Conall O'Brien <conall@conall.net>
@conallob conallob changed the title Unify error messages and adopt wrapping error messages, part 1 Unify error messages and prepare to adopt wrapping error messages, part 1 May 16, 2023
…errors

Signed-off-by: Conall O'Brien <conall@conall.net>
@conallob
Copy link
Contributor Author

#522 was intended to be a complimentary PR, but I managed to goof the git branches, so all changes are now in this PR

PTAL

@conallob conallob requested a review from SuperQ May 16, 2023 16:00
Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

There are still a lot of errors that drop the original context of what part of parsing failed. Please make sure that we keep the original details of the parsing error intact.

I've highlighted a number of them.

arp.go Outdated Show resolved Hide resolved
buddyinfo.go Outdated Show resolved Hide resolved
buddyinfo.go Outdated Show resolved Hide resolved
crypto.go Outdated Show resolved Hide resolved
fscache.go Show resolved Hide resolved
loadavg.go Outdated Show resolved Hide resolved
mdstat.go Outdated Show resolved Hide resolved
@conallob
Copy link
Contributor Author

Thanks, I have been fixing up entries that didn't give specifics, but I may have missed a few early on

@conallob
Copy link
Contributor Author

Fixed up all the vague, non specific errors (grep "fmt.Errorf" *.go | grep -e "%s: %.: %w" confirms they're all gone)

I do have 2 commits which aren't DCO signed (should work out how to config that per repository) and I'm not sure how to amend those commits

SuperQ and others added 9 commits May 23, 2023 11:32
* Update Go to 1.20.
* Update minimum Go to 1.19.
* Update Go modules.
* Fix deprecated os/ioutil use.

Signed-off-by: Ben Kochie <superq@gmail.com>
* add CpusAllowedList for /proc/[pid]/status

Signed-off-by: mn.albeschenko <albeschenko.work@gmail.com>

* Fix documentation comment

Co-authored-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Johannes 'fish' Ziemke <github@5pi.de>

---------

Signed-off-by: mn.albeschenko <albeschenko.work@gmail.com>
Signed-off-by: Johannes 'fish' Ziemke <github@5pi.de>
Co-authored-by: Johannes 'fish' Ziemke <github@5pi.de>
Co-authored-by: Ben Kochie <superq@gmail.com>
#483 introduced a bug
that terminates attribute reading when the returned error is
syscall.Errno, which is what util.SysReadFile() will typically
return. Handle that case specifically.

While doing that pull the error checking into
ParseNetClassAttribute() for clarity and to allow external
callers to handle errors correctly.

Signed-off-by: Dan Williams <dcbw@redhat.com>
…ment

Signed-off-by: Conall O'Brien <conall@conall.net>
Signed-off-by: Conall O'Brien <conall@conall.net>
This reverts commit 5a7050c.

Signed-off-by: Conall O'Brien <conall@conall.net>
Signed-off-by: Conall O'Brien <conall@conall.net>
…is (#523)

Other projects that import procfs, like node_exporter, apparently build
for OSs that don't have Statfs_t.Type.

Signed-off-by: Dan Williams <dcbw@redhat.com>
When parsing older kernel versoins, we assume the CPU is indexed based
on the parsed line, rather than an explicit index column.

Signed-off-by: Ben Kochie <superq@gmail.com>
@conallob conallob closed this by deleting the head repository May 23, 2023
@conallob
Copy link
Contributor Author

Recreated as #526 , but without all the messed up git history

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.

7 participants