Skip to content

Commit 0a3482b

Browse files
authored
Merge pull request #206 from koba1t/remove_unmaintained_error_pkg
remove unmaintained errors pkg(github.com/pkg/errors)
2 parents e7cfbbb + 106306d commit 0a3482b

File tree

4 files changed

+111
-117
lines changed

4 files changed

+111
-117
lines changed

patch.go

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package jsonpatch
33
import (
44
"bytes"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"strconv"
89
"strings"
9-
10-
"github.com/pkg/errors"
1110
)
1211

1312
const (
@@ -277,7 +276,7 @@ func (o Operation) Path() (string, error) {
277276
return op, nil
278277
}
279278

280-
return "unknown", errors.Wrapf(ErrMissing, "operation missing path field")
279+
return "unknown", fmt.Errorf("operation missing path field: %w", ErrMissing)
281280
}
282281

283282
// From reads the "from" field of the Operation.
@@ -294,7 +293,7 @@ func (o Operation) From() (string, error) {
294293
return op, nil
295294
}
296295

297-
return "unknown", errors.Wrapf(ErrMissing, "operation, missing from field")
296+
return "unknown", fmt.Errorf("operation, missing from field: %w", ErrMissing)
298297
}
299298

300299
func (o Operation) value() *lazyNode {
@@ -319,7 +318,7 @@ func (o Operation) ValueInterface() (interface{}, error) {
319318
return v, nil
320319
}
321320

322-
return nil, errors.Wrapf(ErrMissing, "operation, missing value field")
321+
return nil, fmt.Errorf("operation, missing value field: %w", ErrMissing)
323322
}
324323

325324
func isArray(buf []byte) bool {
@@ -398,7 +397,7 @@ func (d *partialDoc) get(key string) (*lazyNode, error) {
398397
func (d *partialDoc) remove(key string) error {
399398
_, ok := (*d)[key]
400399
if !ok {
401-
return errors.Wrapf(ErrMissing, "Unable to remove nonexistent key: %s", key)
400+
return fmt.Errorf("Unable to remove nonexistent key: %s: %w", key, ErrMissing)
402401
}
403402

404403
delete(*d, key)
@@ -415,10 +414,10 @@ func (d *partialArray) set(key string, val *lazyNode) error {
415414

416415
if idx < 0 {
417416
if !SupportNegativeIndices {
418-
return errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
417+
return fmt.Errorf("Unable to access invalid index: %d : %w", idx, ErrInvalidIndex)
419418
}
420419
if idx < -len(*d) {
421-
return errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
420+
return fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
422421
}
423422
idx += len(*d)
424423
}
@@ -435,7 +434,7 @@ func (d *partialArray) add(key string, val *lazyNode) error {
435434

436435
idx, err := strconv.Atoi(key)
437436
if err != nil {
438-
return errors.Wrapf(err, "value was not a proper array index: '%s'", key)
437+
return fmt.Errorf("value was not a proper array index: '%s': %w", key, err)
439438
}
440439

441440
sz := len(*d) + 1
@@ -445,15 +444,15 @@ func (d *partialArray) add(key string, val *lazyNode) error {
445444
cur := *d
446445

447446
if idx >= len(ary) {
448-
return errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
447+
return fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
449448
}
450449

451450
if idx < 0 {
452451
if !SupportNegativeIndices {
453-
return errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
452+
return fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
454453
}
455454
if idx < -len(ary) {
456-
return errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
455+
return fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
457456
}
458457
idx += len(ary)
459458
}
@@ -475,16 +474,16 @@ func (d *partialArray) get(key string) (*lazyNode, error) {
475474

476475
if idx < 0 {
477476
if !SupportNegativeIndices {
478-
return nil, errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
477+
return nil, fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
479478
}
480479
if idx < -len(*d) {
481-
return nil, errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
480+
return nil, fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
482481
}
483482
idx += len(*d)
484483
}
485484

486485
if idx >= len(*d) {
487-
return nil, errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
486+
return nil, fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
488487
}
489488

490489
return (*d)[idx], nil
@@ -499,15 +498,15 @@ func (d *partialArray) remove(key string) error {
499498
cur := *d
500499

501500
if idx >= len(cur) {
502-
return errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
501+
return fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
503502
}
504503

505504
if idx < 0 {
506505
if !SupportNegativeIndices {
507-
return errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
506+
return fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
508507
}
509508
if idx < -len(cur) {
510-
return errors.Wrapf(ErrInvalidIndex, "Unable to access invalid index: %d", idx)
509+
return fmt.Errorf("Unable to access invalid index: %d: %w", idx, ErrInvalidIndex)
511510
}
512511
idx += len(cur)
513512
}
@@ -525,18 +524,18 @@ func (d *partialArray) remove(key string) error {
525524
func (p Patch) add(doc *container, op Operation) error {
526525
path, err := op.Path()
527526
if err != nil {
528-
return errors.Wrapf(ErrMissing, "add operation failed to decode path")
527+
return fmt.Errorf("add operation failed to decode path: %w", ErrMissing)
529528
}
530529

531530
con, key := findObject(doc, path)
532531

533532
if con == nil {
534-
return errors.Wrapf(ErrMissing, "add operation does not apply: doc is missing path: \"%s\"", path)
533+
return fmt.Errorf("add operation does not apply: doc is missing path: \"%s\": %w", path, ErrMissing)
535534
}
536535

537536
err = con.add(key, op.value())
538537
if err != nil {
539-
return errors.Wrapf(err, "error in add for path: '%s'", path)
538+
return fmt.Errorf("error in add for path: '%s': %w", path, err)
540539
}
541540

542541
return nil
@@ -545,18 +544,18 @@ func (p Patch) add(doc *container, op Operation) error {
545544
func (p Patch) remove(doc *container, op Operation) error {
546545
path, err := op.Path()
547546
if err != nil {
548-
return errors.Wrapf(ErrMissing, "remove operation failed to decode path")
547+
return fmt.Errorf("remove operation failed to decode path: %w", ErrMissing)
549548
}
550549

551550
con, key := findObject(doc, path)
552551

553552
if con == nil {
554-
return errors.Wrapf(ErrMissing, "remove operation does not apply: doc is missing path: \"%s\"", path)
553+
return fmt.Errorf("remove operation does not apply: doc is missing path: \"%s\": %w", path, ErrMissing)
555554
}
556555

557556
err = con.remove(key)
558557
if err != nil {
559-
return errors.Wrapf(err, "error in remove for path: '%s'", path)
558+
return fmt.Errorf("error in remove for path: '%s': %w", path, err)
560559
}
561560

562561
return nil
@@ -565,7 +564,7 @@ func (p Patch) remove(doc *container, op Operation) error {
565564
func (p Patch) replace(doc *container, op Operation) error {
566565
path, err := op.Path()
567566
if err != nil {
568-
return errors.Wrapf(err, "replace operation failed to decode path")
567+
return fmt.Errorf("replace operation failed to decode path: %w", err)
569568
}
570569

571570
if path == "" {
@@ -574,7 +573,7 @@ func (p Patch) replace(doc *container, op Operation) error {
574573
if val.which == eRaw {
575574
if !val.tryDoc() {
576575
if !val.tryAry() {
577-
return errors.Wrapf(err, "replace operation value must be object or array")
576+
return fmt.Errorf("replace operation value must be object or array: %w", err)
578577
}
579578
}
580579
}
@@ -585,7 +584,7 @@ func (p Patch) replace(doc *container, op Operation) error {
585584
case eDoc:
586585
*doc = &val.doc
587586
case eRaw:
588-
return errors.Wrapf(err, "replace operation hit impossible case")
587+
return fmt.Errorf("replace operation hit impossible case: %w", err)
589588
}
590589

591590
return nil
@@ -594,17 +593,17 @@ func (p Patch) replace(doc *container, op Operation) error {
594593
con, key := findObject(doc, path)
595594

596595
if con == nil {
597-
return errors.Wrapf(ErrMissing, "replace operation does not apply: doc is missing path: %s", path)
596+
return fmt.Errorf("replace operation does not apply: doc is missing path: %s: %w", path, ErrMissing)
598597
}
599598

600599
_, ok := con.get(key)
601600
if ok != nil {
602-
return errors.Wrapf(ErrMissing, "replace operation does not apply: doc is missing key: %s", path)
601+
return fmt.Errorf("replace operation does not apply: doc is missing key: %s: %w", path, ErrMissing)
603602
}
604603

605604
err = con.set(key, op.value())
606605
if err != nil {
607-
return errors.Wrapf(err, "error in remove for path: '%s'", path)
606+
return fmt.Errorf("error in remove for path: '%s': %w", path, err)
608607
}
609608

610609
return nil
@@ -613,39 +612,39 @@ func (p Patch) replace(doc *container, op Operation) error {
613612
func (p Patch) move(doc *container, op Operation) error {
614613
from, err := op.From()
615614
if err != nil {
616-
return errors.Wrapf(err, "move operation failed to decode from")
615+
return fmt.Errorf("move operation failed to decode from: %w", err)
617616
}
618617

619618
con, key := findObject(doc, from)
620619

621620
if con == nil {
622-
return errors.Wrapf(ErrMissing, "move operation does not apply: doc is missing from path: %s", from)
621+
return fmt.Errorf("move operation does not apply: doc is missing from path: %s: %w", from, ErrMissing)
623622
}
624623

625624
val, err := con.get(key)
626625
if err != nil {
627-
return errors.Wrapf(err, "error in move for path: '%s'", key)
626+
return fmt.Errorf("error in move for path: '%s': %w", key, err)
628627
}
629628

630629
err = con.remove(key)
631630
if err != nil {
632-
return errors.Wrapf(err, "error in move for path: '%s'", key)
631+
return fmt.Errorf("error in move for path: '%s': %w", key, err)
633632
}
634633

635634
path, err := op.Path()
636635
if err != nil {
637-
return errors.Wrapf(err, "move operation failed to decode path")
636+
return fmt.Errorf("move operation failed to decode path: %w", err)
638637
}
639638

640639
con, key = findObject(doc, path)
641640

642641
if con == nil {
643-
return errors.Wrapf(ErrMissing, "move operation does not apply: doc is missing destination path: %s", path)
642+
return fmt.Errorf("move operation does not apply: doc is missing destination path: %s: %w", path, ErrMissing)
644643
}
645644

646645
err = con.add(key, val)
647646
if err != nil {
648-
return errors.Wrapf(err, "error in move for path: '%s'", path)
647+
return fmt.Errorf("error in move for path: '%s': %w", path, err)
649648
}
650649

651650
return nil
@@ -654,7 +653,7 @@ func (p Patch) move(doc *container, op Operation) error {
654653
func (p Patch) test(doc *container, op Operation) error {
655654
path, err := op.Path()
656655
if err != nil {
657-
return errors.Wrapf(err, "test operation failed to decode path")
656+
return fmt.Errorf("test operation failed to decode path: %w", err)
658657
}
659658

660659
if path == "" {
@@ -673,67 +672,67 @@ func (p Patch) test(doc *container, op Operation) error {
673672
return nil
674673
}
675674

676-
return errors.Wrapf(ErrTestFailed, "testing value %s failed", path)
675+
return fmt.Errorf("testing value %s failed: %w", path, ErrTestFailed)
677676
}
678677

679678
con, key := findObject(doc, path)
680679

681680
if con == nil {
682-
return errors.Wrapf(ErrMissing, "test operation does not apply: is missing path: %s", path)
681+
return fmt.Errorf("test operation does not apply: is missing path: %s: %w", path, ErrMissing)
683682
}
684683

685684
val, err := con.get(key)
686685
if err != nil {
687-
return errors.Wrapf(err, "error in test for path: '%s'", path)
686+
return fmt.Errorf("error in test for path: '%s': %w", path, err)
688687
}
689688

690689
if val == nil {
691690
if op.value() == nil || op.value().raw == nil {
692691
return nil
693692
}
694-
return errors.Wrapf(ErrTestFailed, "testing value %s failed", path)
693+
return fmt.Errorf("testing value %s failed: %w", path, ErrTestFailed)
695694
} else if op.value() == nil {
696-
return errors.Wrapf(ErrTestFailed, "testing value %s failed", path)
695+
return fmt.Errorf("testing value %s failed: %w", path, ErrTestFailed)
697696
}
698697

699698
if val.equal(op.value()) {
700699
return nil
701700
}
702701

703-
return errors.Wrapf(ErrTestFailed, "testing value %s failed", path)
702+
return fmt.Errorf("testing value %s failed: %w", path, ErrTestFailed)
704703
}
705704

706705
func (p Patch) copy(doc *container, op Operation, accumulatedCopySize *int64) error {
707706
from, err := op.From()
708707
if err != nil {
709-
return errors.Wrapf(err, "copy operation failed to decode from")
708+
return fmt.Errorf("copy operation failed to decode from: %w", err)
710709
}
711710

712711
con, key := findObject(doc, from)
713712

714713
if con == nil {
715-
return errors.Wrapf(ErrMissing, "copy operation does not apply: doc is missing from path: %s", from)
714+
return fmt.Errorf("copy operation does not apply: doc is missing from path: %s: %w", from, ErrMissing)
716715
}
717716

718717
val, err := con.get(key)
719718
if err != nil {
720-
return errors.Wrapf(err, "error in copy for from: '%s'", from)
719+
return fmt.Errorf("error in copy for from: '%s': %w", from, err)
721720
}
722721

723722
path, err := op.Path()
724723
if err != nil {
725-
return errors.Wrapf(ErrMissing, "copy operation failed to decode path")
724+
return fmt.Errorf("copy operation failed to decode path: %w", ErrMissing)
726725
}
727726

728727
con, key = findObject(doc, path)
729728

730729
if con == nil {
731-
return errors.Wrapf(ErrMissing, "copy operation does not apply: doc is missing destination path: %s", path)
730+
return fmt.Errorf("copy operation does not apply: doc is missing destination path: %s: %w", path, ErrMissing)
732731
}
733732

734733
valCopy, sz, err := deepCopy(val)
735734
if err != nil {
736-
return errors.Wrapf(err, "error while performing deep copy")
735+
return fmt.Errorf("error while performing deep copy: %w", err)
737736
}
738737

739738
(*accumulatedCopySize) += int64(sz)
@@ -743,7 +742,7 @@ func (p Patch) copy(doc *container, op Operation, accumulatedCopySize *int64) er
743742

744743
err = con.add(key, valCopy)
745744
if err != nil {
746-
return errors.Wrapf(err, "error while adding value during copy")
745+
return fmt.Errorf("error while adding value during copy: %w", err)
747746
}
748747

749748
return nil

v5/go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ module github.com/evanphx/json-patch/v5
22

33
go 1.18
44

5-
require (
6-
github.com/jessevdk/go-flags v1.4.0
7-
github.com/pkg/errors v0.8.1
8-
)
5+
require github.com/jessevdk/go-flags v1.4.0

v5/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
22
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
3-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
4-
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

0 commit comments

Comments
 (0)