Comments (9)
I'd be open to ApplyWithOptions
, I think that's ok.
from json-patch.
@evanphx - I will be submitting a PR for this issue soon.
from json-patch.
I'd rather not continue to add these toplevel options. I think the right solution is, instead, to accumulate errors found trying to apply the patch and then return them all at once. That would allow you the ability to inspect the errors and disregard the error if they were all for removing a non-existentant path.
from json-patch.
Just to make sure I understand, are you suggesting to change the signature of func (p Patch) Apply(doc []byte) ([]byte, error)
to func (p Patch) Apply(doc []byte) ([]byte, []error)
?
Won’t this break existing clients?
Or are you thinking a new method?
Also, in order for this to work, it sounds like the method will be returning both a patched document and a slice of errors, so in case of errors will it just ignore the errored operations and just keep going, effectively returning a partially patched document? How will the user inspect the errors? By error type? Will this require the introduction of a new error type/types to capture the type of the offending operation?
In addition, how will hard errors such as the ones returned by json.Unmarshal
, json.Marshal
and json.MarshalIndent
fit in this new approach?
from json-patch.
No, Apply
would still return ([]byte, error)
but within Apply
, we'd accumulate the errors and then return, say, a PatchError
type that contains all the accumulated errors.
I think that the non-patch related errors like the ones returned from json.Marshal
would be "hard" errors, returning immediately.
from json-patch.
My only concern is that changing the type of the error returned by Apply might still break existing clients who are already inspecting the type/contents of the error.
I’m also wondering if there is any value in partially patched documents. What I mean is, “remove-missing-path” is the only missing-path related error that I can see that might be semantically benign and could be ignored for certain use cases.
If the goal is to avoid package-level global flags, can I suggest introducing a new method ApplyWithOptions instead? It will have a signature similar to Apply, except it will also accept a new parameter struct type (say ApplyOptions) with the same options you already have as global vars plus the new AllowMissingPathOnRemove. Apply can be modified to simply call ApplyWithOptions by passing the current global options through the ApplyOptions parameter.
This way you preserve backward compatibility of the current Apply (including error semantics), avoid introducing a new global variable and have an alternative method which takes call-level options.
from json-patch.
We'd be changing the concrete type only, the exposed type would still be error
. No one is dependent on the concrete type returned now I doubt. And even if they are, I'm ok breaking that contract.
from json-patch.
I’ll put together a PR.
from json-patch.
Closing in favor of #117.
from json-patch.
Related Issues (20)
- Performance Degradation Starting In v5.2.0 HOT 2
- Invalid spec implementation
- RFC Link in README.md returns a 404 error
- nil dereference on empty "replace" on root
- RFC6902 limitations when the document structure is not known in advance HOT 2
- Panic when adding to a non-existing array HOT 1
- jsonpatch.Equal : strange behavior on handling literal unicode string equality HOT 1
- replace operation does not apply: doc is missing path: missing value HOT 2
- github.com/pkg/errors is in maintenance mode HOT 7
- Is this project still maintained:) HOT 1
- Add validation for pre-flight checks HOT 6
- Unable to access invalid index: 1: invalid index referenced HOT 2
- Can not run "add" on root object
- CreateMergePatch: Numbers may get truncated due to always being treated as float64 HOT 3
- move fails with "missing value" if from is "" HOT 4
- `>` character is not decoded properly when applying json patches HOT 3
- Regression in 5.8.0: cannot create `jsonpatch.Operation` object HOT 6
- add on `null` does not work anymore ? HOT 10
- For V4 and V5, the apply results of the values that do not exist in replace are inconsistent. HOT 1
- Dependency github.com/pkg/errors was archived HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-patch.