Repository navigation
Replies: 1 comment 1 reply
|
It seems like provenance is what you're looking for, here; see #1197. It would ideally be able to answer questions like: where was this value initialized? How was it transformed? But, as a general comment, it's a much better experience to put validation as close to your users as possible. For example, assuming you have a public API, put type constraints on those properties which compute the derived value, and adds constraints on them. E.g. do this: userInput: String(convertValue(this).startsWith("foo"))?
// internal library code
function convertValue(name: String): String = TODO()
fixed internallyDerivedValue: Derived = new {
when (userInput != null) {
derivedInput = convertValue(userInput)
}
}
class Derived {
derivedInput: String?
}Instead of this: userInput: String?
// internal library code
function convertValue(name: String): String = TODO()
fixed internallyDerivedValue: Derived = new {
when (userInput != null) {
derivedInput = convertValue(userInput)
}
}
class Derived {
derivedInput: String(startsWith("foo"))?
} |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
While pkl provides very good errors when type errors are present in amended files, there doesn't seem to a good way of raising more 'helpful' errors when you're doing complicated validation or rendering.
The project I'm using Pkl for takes amended files and transforms them while also applying logical validation that I can't really do with just typealiases. Some classes do not create valid output in some environments, and thus I'm checking to ensure that those classes are only usable where they are supposed to be.
Where I am able to detect logic issues and call
throw(), the stacktrace shows the call originating from my customrender()(not an output renderer), and not from the data that is actually responsible. While this is expected behaviour, I'd much rather generate a friendlier error from where the invalid data actually originated from, as the end-user won't immediately know what line in the amended files has caused the problem.For context, my amended files extend from something somewhat like this, sans a lot of other classes:
In this example for just
sometimesUsableField, I could apply restrictions to the listing and ensure that!some((rf) -> rf.onlyInEnvironments?.contains(TARGETENV) ?? true)and raise closer to the actual data (at least I'd be outside of the rendering code), however I have a lot of field classes that I'd ideally like to impose multiple restrictions as well as multiple types of restrictions to ensure an invalid output file is nearly impossible.The data I'm transforming isn't mutated heavily so there's still a pointer to the original field in the amended file so
throw()could be given custom context for why an error has actually occoured. So if Pkl had a more sophisticated version ofError.captureStackTrace, I could get a friendlier error that way.All reactions