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

Refactor ErrorObject and Error classes' initialization #849

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

st0012
Copy link
Member

@st0012 st0012 commented May 3, 2020

Currently, we allow raising errors from vm with any given string, like

t.vm.InitErrorObject("ErrorWithoutAClass", ....)

This is a bad practice because any internal error should have a corresponding error class.

This PR fixes this by only accepting pre-defined error types (enum) when initializing error objects. It also checks every error type (int) has a corresponding name (string) during vm initialization, which saves us the work to visually sync the 2 lists manually.

@st0012 st0012 added this to the version 0.1.14 milestone May 3, 2020
@st0012 st0012 self-assigned this May 3, 2020
vm/errors/error.go Show resolved Hide resolved
vm/errors/error.go Show resolved Hide resolved
vm/errors/error.go Show resolved Hide resolved
vm/errors/error.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 3, 2020

Codecov Report

Merging #849 into master will increase coverage by 0.00%.
The diff coverage is 93.33%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #849   +/-   ##
=======================================
  Coverage   81.02%   81.03%           
=======================================
  Files          54       54           
  Lines        7496     7498    +2     
=======================================
+ Hits         6074     6076    +2     
  Misses       1188     1188           
  Partials      234      234           
Impacted Files Coverage Δ
vm/issue_vm.go 0.00% <0.00%> (ø)
vm/class.go 86.35% <100.00%> (ø)
vm/error.go 72.72% <100.00%> (+1.75%) ⬆️
vm/thread.go 90.45% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44f3a14...d2b2734. Read the comment docs.

@@ -22,7 +22,6 @@ type Error struct {
message string
stackTraces []string
storedTraces bool
Type string
Copy link
Member Author

Choose a reason for hiding this comment

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

The Type attribute is essentially the error's class name. So we don't need to store it separately.

@st0012 st0012 force-pushed the refactor-errors branch from 2d9c0a2 to a77e13f Compare May 3, 2020 09:47
vm/errors/error.go Outdated Show resolved Hide resolved
vm/errors/error.go Outdated Show resolved Hide resolved
Currently, we allow raising errors from vm with any given string. This
is a bad practice because any internal error should have a corresponding
error class.

This PR fixes this by only accepting pre-defined error types (enum) when
initializing error objects. It also checks every error type (int) has a
corresponding name (string) during vm initialization, which saves us the
work to visually sync the 2 lists manually.
@st0012 st0012 force-pushed the refactor-errors branch from a77e13f to d2b2734 Compare May 3, 2020 09:48
@st0012 st0012 requested a review from 64kramsystem May 3, 2020 09:49
Copy link
Member

@64kramsystem 64kramsystem left a comment

Choose a reason for hiding this comment

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

For some reason, I'm not 100% convinced of the new logic. If the purpose is to avoid:

raising errors from vm with any given string, [...] This is a bad practice because any internal error should have a corresponding error class

wouldn't defining the ErrorType type to string do the work? the enum could then use ErrorType rather than plain strings.

I'm not familiar with Go, so I may be wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants