From 5edf89cf3d814235f75fc2e8519d4c756fe5bf55 Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Wed, 14 Sep 2016 13:11:28 -0700 Subject: [PATCH] Replace d.Chk.True with d.PanicIfFalse (#2563) And same for d.Chk.False --- go/chunks/chunk.go | 2 +- go/chunks/chunk_serializer.go | 12 +++---- go/chunks/dynamo_store.go | 18 +++++------ go/chunks/leveldb_store.go | 16 +++++----- go/chunks/memory_store.go | 2 +- go/d/try.go | 35 ++++++++++++++------- go/d/try_test.go | 34 ++++++++++++++++++++ go/datas/commit.go | 6 ++-- go/datas/database_common.go | 4 +-- go/datas/database_server.go | 2 +- go/datas/http_batch_store.go | 10 +++--- go/datas/local_database.go | 2 +- go/datas/pull.go | 8 ++--- go/datas/remote_database_client.go | 2 +- go/datas/serialize_hints.go | 4 +-- go/dataset/dataset.go | 4 +-- go/hash/hash.go | 2 +- go/perf/codec-perf-rig/main.go | 2 +- go/spec/ref_counting_ldb_store.go | 2 +- go/types/blob.go | 6 ++-- go/types/codec.go | 4 +-- go/types/indexed_sequences.go | 4 +-- go/types/list.go | 10 +++--- go/types/list_iterator.go | 2 +- go/types/map.go | 6 ++-- go/types/mapMutator.go | 4 +-- go/types/meta_sequence.go | 8 ++--- go/types/opcache_compare.go | 4 +-- go/types/ordered_sequences.go | 8 ++--- go/types/ordered_sequences_diff.go | 4 +-- go/types/path.go | 4 +-- go/types/ref.go | 4 +-- go/types/sequence_chunker.go | 14 ++++----- go/types/sequence_cursor.go | 8 ++--- go/types/setMutator.go | 4 +-- go/types/struct.go | 2 +- go/types/type_cache.go | 2 +- go/types/value_decoder.go | 2 +- go/types/value_encoder.go | 4 +-- go/types/value_store.go | 6 ++-- go/util/orderedparallel/ordered_parallel.go | 2 +- go/util/sizecache/size_cache.go | 2 +- go/walk/walk.go | 6 ++-- samples/go/csv/read.go | 2 +- samples/go/demo-server/main.go | 2 +- samples/go/nomsfs/nomsfs.go | 2 +- tools/file/file.go | 2 +- 47 files changed, 171 insertions(+), 124 deletions(-) diff --git a/go/chunks/chunk.go b/go/chunks/chunk.go index 3250c1103b..6c5ea3bbc7 100644 --- a/go/chunks/chunk.go +++ b/go/chunks/chunk.go @@ -57,7 +57,7 @@ func NewChunkWriter() *ChunkWriter { } func (w *ChunkWriter) Write(data []byte) (int, error) { - d.Chk.True(w.buffer != nil, "Write() cannot be called after Hash() or Close().") + d.PanicIfFalse(w.buffer != nil, "Write() cannot be called after Hash() or Close().") size, err := w.buffer.Write(data) d.Chk.NoError(err) return size, nil diff --git a/go/chunks/chunk_serializer.go b/go/chunks/chunk_serializer.go index ebe5265853..27f36cd1db 100644 --- a/go/chunks/chunk_serializer.go +++ b/go/chunks/chunk_serializer.go @@ -29,12 +29,12 @@ import ( // Serialize a single Chunk to writer. func Serialize(chunk Chunk, writer io.Writer) { - d.Chk.True(chunk.data != nil) + d.PanicIfFalse(chunk.data != nil) digest := chunk.Hash().Digest() n, err := io.Copy(writer, bytes.NewReader(digest[:])) d.Chk.NoError(err) - d.Chk.True(int64(hash.ByteLen) == n) + d.PanicIfFalse(int64(hash.ByteLen) == n) // Because of chunking at higher levels, no chunk should never be more than 4GB chunkSize := uint32(len(chunk.Data())) @@ -43,7 +43,7 @@ func Serialize(chunk Chunk, writer io.Writer) { n, err = io.Copy(writer, bytes.NewReader(chunk.Data())) d.Chk.NoError(err) - d.Chk.True(uint32(n) == chunkSize) + d.PanicIfFalse(uint32(n) == chunkSize) } // Deserialize reads off of |reader| until EOF, sending chunks to |cs|. If |rateLimit| is non-nill, concurrency will be limited to the available capacity of the channel. @@ -91,7 +91,7 @@ func deserializeChunk(reader io.Reader) (Chunk, bool) { return EmptyChunk, false } d.Chk.NoError(err) - d.Chk.True(int(hash.ByteLen) == n) + d.PanicIfFalse(int(hash.ByteLen) == n) h := hash.New(digest) chunkSize := uint32(0) @@ -101,8 +101,8 @@ func deserializeChunk(reader io.Reader) (Chunk, bool) { w := NewChunkWriter() n2, err := io.CopyN(w, reader, int64(chunkSize)) d.Chk.NoError(err) - d.Chk.True(int64(chunkSize) == n2) + d.PanicIfFalse(int64(chunkSize) == n2) c := w.Chunk() - d.Chk.True(h == c.Hash(), "%s != %s", h, c.Hash()) + d.PanicIfFalse(h == c.Hash(), "%s != %s", h, c.Hash()) return c, true } diff --git a/go/chunks/dynamo_store.go b/go/chunks/dynamo_store.go index 7779c786f9..6a9d88acf8 100644 --- a/go/chunks/dynamo_store.go +++ b/go/chunks/dynamo_store.go @@ -237,10 +237,10 @@ func (s *DynamoStore) buildRequestItems(hashes map[hash.Hash]bool) map[string]*d func (s *DynamoStore) processResponses(responses []map[string]*dynamodb.AttributeValue, batch ReadBatch) { for _, item := range responses { p := item[refAttr] - d.Chk.True(p != nil) + d.PanicIfFalse(p != nil) r := hash.FromSlice(s.removeNamespace(p.B)) p = item[chunkAttr] - d.Chk.True(p != nil) + d.PanicIfFalse(p != nil) b := p.B if p = item[compAttr]; p != nil && *p.S == gzipValue { gr, err := gzip.NewReader(bytes.NewReader(b)) @@ -400,9 +400,9 @@ func (s *DynamoStore) Version() string { if itemLen == 0 { return constants.NomsVersion } - d.Chk.True(itemLen == 2, "Version should have 2 attributes on it: %+v", result.Item) - d.Chk.True(result.Item[numAttr] != nil) - d.Chk.True(result.Item[numAttr].S != nil) + d.PanicIfFalse(itemLen == 2, "Version should have 2 attributes on it: %+v", result.Item) + d.PanicIfFalse(result.Item[numAttr] != nil) + d.PanicIfFalse(result.Item[numAttr].S != nil) return aws.StringValue(result.Item[numAttr].S) } @@ -440,11 +440,11 @@ func (s *DynamoStore) Root() hash.Hash { if itemLen == 0 { return hash.Hash{} } - d.Chk.True(itemLen == 2 || itemLen == 3, "Root should have 2 or three attributes on it: %+v", result.Item) + d.PanicIfFalse(itemLen == 2 || itemLen == 3, "Root should have 2 or three attributes on it: %+v", result.Item) if itemLen == 3 { - d.Chk.True(result.Item[compAttr] != nil) - d.Chk.True(result.Item[compAttr].S != nil) - d.Chk.True(noneValue == *result.Item[compAttr].S) + d.PanicIfFalse(result.Item[compAttr] != nil) + d.PanicIfFalse(result.Item[compAttr].S != nil) + d.PanicIfFalse(noneValue == *result.Item[compAttr].S) } return hash.FromSlice(result.Item[chunkAttr].B) } diff --git a/go/chunks/leveldb_store.go b/go/chunks/leveldb_store.go index de01a24a88..bc7c92ee2a 100644 --- a/go/chunks/leveldb_store.go +++ b/go/chunks/leveldb_store.go @@ -77,39 +77,39 @@ type LevelDBStore struct { } func (l *LevelDBStore) Root() hash.Hash { - d.Chk.True(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") + d.PanicIfFalse(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") return l.rootByKey(l.rootKey) } func (l *LevelDBStore) UpdateRoot(current, last hash.Hash) bool { - d.Chk.True(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") + d.PanicIfFalse(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") l.versionSetOnce.Do(l.setVersIfUnset) return l.updateRootByKey(l.rootKey, current, last) } func (l *LevelDBStore) Get(ref hash.Hash) Chunk { - d.Chk.True(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") + d.PanicIfFalse(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") return l.getByKey(l.toChunkKey(ref), ref) } func (l *LevelDBStore) Has(ref hash.Hash) bool { - d.Chk.True(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") + d.PanicIfFalse(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") return l.hasByKey(l.toChunkKey(ref)) } func (l *LevelDBStore) Version() string { - d.Chk.True(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") + d.PanicIfFalse(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") return l.versByKey(l.versionKey) } func (l *LevelDBStore) Put(c Chunk) { - d.Chk.True(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") + d.PanicIfFalse(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") l.versionSetOnce.Do(l.setVersIfUnset) l.putByKey(l.toChunkKey(c.Hash()), c) } func (l *LevelDBStore) PutMany(chunks []Chunk) (e BackpressureError) { - d.Chk.True(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") + d.PanicIfFalse(l.internalLevelDBStore != nil, "Cannot use LevelDBStore after Close().") l.versionSetOnce.Do(l.setVersIfUnset) numBytes := 0 b := new(leveldb.Batch) @@ -267,7 +267,7 @@ type LevelDBStoreFactory struct { } func (f *LevelDBStoreFactory) CreateStore(ns string) ChunkStore { - d.Chk.True(f.store != nil, "Cannot use LevelDBStoreFactory after Shutter().") + d.PanicIfFalse(f.store != nil, "Cannot use LevelDBStoreFactory after Shutter().") return newLevelDBStore(f.store, []byte(ns), false) } diff --git a/go/chunks/memory_store.go b/go/chunks/memory_store.go index 5ef24d82e5..f02721fdcb 100644 --- a/go/chunks/memory_store.go +++ b/go/chunks/memory_store.go @@ -81,7 +81,7 @@ type MemoryStoreFactory struct { } func (f *MemoryStoreFactory) CreateStore(ns string) ChunkStore { - d.Chk.True(f.stores != nil, "Cannot use MemoryStore after Shutter().") + d.PanicIfFalse(f.stores != nil, "Cannot use MemoryStore after Shutter().") if cs, present := f.stores[ns]; present { return cs } diff --git a/go/d/try.go b/go/d/try.go index e062b1bef2..541ed8d6cc 100644 --- a/go/d/try.go +++ b/go/d/try.go @@ -6,11 +6,10 @@ package d import ( + "errors" "fmt" "reflect" - "errors" - "github.com/attic-labs/testify/assert" ) @@ -34,16 +33,30 @@ func PanicIfError(err error) { } } -// If b evaluates to true, creates an error using msg and args, wraps it and panics. -func PanicIfTrue(b bool, msg string, args ...interface{}) { +func argsToError(def string, args ...interface{}) error { + if len(args) == 0 { + return errors.New(def) + } + msg := args[0].(string) + if len(args) > 1 { + return fmt.Errorf(msg, args[1:]...) + } + return errors.New(msg) +} + +// If b is true, creates an error using args, wraps it and panics. If args is provided the first +// value must be a string. +func PanicIfTrue(b bool, args ...interface{}) { if b { - var err error - if len(args) > 0 { - err = fmt.Errorf(msg, args...) - } else { - err = errors.New(msg) - } - panic(Wrap(err)) + panic(Wrap(argsToError("Expected true", args...))) + } +} + +// If b is false, creates an error using args, wraps it and panics. If args is provided the first +// value must be a string. +func PanicIfFalse(b bool, args ...interface{}) { + if !b { + panic(Wrap(argsToError("Expected false", args...))) } } diff --git a/go/d/try_test.go b/go/d/try_test.go index 2be64a7f5d..a8b85dbc6e 100644 --- a/go/d/try_test.go +++ b/go/d/try_test.go @@ -128,6 +128,10 @@ func TestPanicIfTrue(t *testing.T) { format := "could be a format: %s" formatted := fmt.Sprintf(format, arg) + assert.Panics(func() { + PanicIfTrue(true) + }) + assert.Panics(func() { PanicIfTrue(true, "Panicking!!!!") }) @@ -147,6 +151,36 @@ func TestPanicIfTrue(t *testing.T) { assert.Equal(errors.New(formatted), Unwrap(err)) } +func TestPanicIfFalse(t *testing.T) { + assert := assert.New(t) + + arg := "arg value" + format := "could be a format: %s" + formatted := fmt.Sprintf(format, arg) + + assert.Panics(func() { + PanicIfFalse(false) + }) + + assert.Panics(func() { + PanicIfFalse(false, "Panicking!!!!") + }) + + assert.NotPanics(func() { + PanicIfFalse(true, "Not panicking") + }) + + err := Try(func() { + PanicIfFalse(false, format) + }) + assert.Equal(errors.New(format), Unwrap(err)) + + err = Try(func() { + PanicIfFalse(false, format, arg) + }) + assert.Equal(errors.New(formatted), Unwrap(err)) +} + func TestPanicIfNotType(t *testing.T) { assert := assert.New(t) diff --git a/go/datas/commit.go b/go/datas/commit.go index 4e43c48bef..8c3f81544e 100644 --- a/go/datas/commit.go +++ b/go/datas/commit.go @@ -136,7 +136,7 @@ func valueTypesFromParents(parents types.Set, fieldName string) []*types.Type { } func getSetElementType(t *types.Type) *types.Type { - d.Chk.True(t.Kind() == types.SetKind) + d.PanicIfFalse(t.Kind() == types.SetKind) return t.Desc.(types.CompoundDesc).ElemTypes[0] } @@ -145,12 +145,12 @@ func fieldTypeFromRefOfCommit(t *types.Type, fieldName string) *types.Type { } func getRefElementType(t *types.Type) *types.Type { - d.Chk.True(t.Kind() == types.RefKind) + d.PanicIfFalse(t.Kind() == types.RefKind) return t.Desc.(types.CompoundDesc).ElemTypes[0] } func fieldTypeFromCommit(t *types.Type, fieldName string) *types.Type { - d.Chk.True(t.Kind() == types.StructKind && t.Desc.(types.StructDesc).Name == "Commit") + d.PanicIfFalse(t.Kind() == types.StructKind && t.Desc.(types.StructDesc).Name == "Commit") return t.Desc.(types.StructDesc).Field(fieldName) } diff --git a/go/datas/database_common.go b/go/datas/database_common.go index b5b555b62a..4828eda97d 100644 --- a/go/datas/database_common.go +++ b/go/datas/database_common.go @@ -46,13 +46,13 @@ func (ds *databaseCommon) MaybeHeadRef(datasetID string) (types.Ref, bool) { func (ds *databaseCommon) Head(datasetID string) types.Struct { c, ok := ds.MaybeHead(datasetID) - d.Chk.True(ok, "Database \"%s\" has no Head.", datasetID) + d.PanicIfFalse(ok, "Database \"%s\" has no Head.", datasetID) return c } func (ds *databaseCommon) HeadRef(datasetID string) types.Ref { r, ok := ds.MaybeHeadRef(datasetID) - d.Chk.True(ok, "Database \"%s\" has no Head.", datasetID) + d.PanicIfFalse(ok, "Database \"%s\" has no Head.", datasetID) return r } diff --git a/go/datas/database_server.go b/go/datas/database_server.go index 3821d9ff03..8a33f5c9a7 100644 --- a/go/datas/database_server.go +++ b/go/datas/database_server.go @@ -120,7 +120,7 @@ func (s *RemoteDatabaseServer) corsHandle(f httprouter.Handle) httprouter.Handle func (s *RemoteDatabaseServer) connState(c net.Conn, cs http.ConnState) { if s.closing { - d.Chk.True(cs == http.StateClosed) + d.PanicIfFalse(cs == http.StateClosed) return } s.csChan <- &connectionState{c, cs} diff --git a/go/datas/http_batch_store.go b/go/datas/http_batch_store.go index e6fb72b011..7ec5da5faf 100644 --- a/go/datas/http_batch_store.go +++ b/go/datas/http_batch_store.go @@ -223,7 +223,7 @@ func (bhcs *httpBatchStore) getRefs(hashes hash.HashSet, batch chunks.ReadBatch) reader := resBodyReader(res) defer closeResponse(reader) - d.Chk.True(http.StatusOK == res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode)) + d.PanicIfFalse(http.StatusOK == res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode)) rl := make(chan struct{}, 16) chunks.Deserialize(reader, &readBatchChunkSink{&batch, &sync.RWMutex{}}, rl) @@ -275,13 +275,13 @@ func (bhcs *httpBatchStore) hasRefs(hashes hash.HashSet, batch chunks.ReadBatch) reader := resBodyReader(res) defer closeResponse(reader) - d.Chk.True(http.StatusOK == res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode)) + d.PanicIfFalse(http.StatusOK == res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode)) scanner := bufio.NewScanner(reader) scanner.Split(bufio.ScanWords) for scanner.Scan() { h := hash.Parse(scanner.Text()) - d.Chk.True(scanner.Scan()) + d.PanicIfFalse(scanner.Scan()) if scanner.Text() == "true" { for _, outstanding := range batch[h] { // This is a little gross, but OutstandingHas.Satisfy() expects a chunk. It ignores it, though, and just sends 'true' over the channel it's holding. @@ -429,7 +429,7 @@ func (bhcs *httpBatchStore) Root() hash.Hash { expectVersion(res) defer closeResponse(res.Body) - d.Chk.True(http.StatusOK == res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode)) + d.PanicIfFalse(http.StatusOK == res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode)) data, err := ioutil.ReadAll(res.Body) d.Chk.NoError(err) return hash.Parse(string(data)) @@ -520,6 +520,6 @@ func closeResponse(rc io.ReadCloser) error { ioutil.ReadAll(rc) // Bug #2069. It's not clear what the behavior is here. These checks are currently not enabled because they are shadowing information about a failure which occurs earlier. // d.Chk.NoError(err) - // d.Chk.True(0 == len(data), string(data)) + // d.PanicIfFalse(0 == len(data), string(data)) return rc.Close() } diff --git a/go/datas/local_database.go b/go/datas/local_database.go index 887bd75962..6c3d22b9c6 100644 --- a/go/datas/local_database.go +++ b/go/datas/local_database.go @@ -46,6 +46,6 @@ func (lds *LocalDatabase) validatingBatchStore() (bs types.BatchStore) { lds.ValueStore = types.NewValueStore(bs) lds.rt = bs } - d.Chk.True(bs.IsValidating()) + d.PanicIfFalse(bs.IsValidating()) return bs } diff --git a/go/datas/pull.go b/go/datas/pull.go index efe5f66754..e1da6a443a 100644 --- a/go/datas/pull.go +++ b/go/datas/pull.go @@ -175,7 +175,7 @@ func planWork(srcQ, sinkQ *types.RefByHeight) (srcRefs, sinkRefs, comRefs types. sinkRefs = popRefsOfHeight(sinkQ, sinkHt) return } - d.Chk.True(srcHt == sinkHt) + d.PanicIfFalse(srcHt == sinkHt) srcRefs, comRefs = findCommon(srcQ, sinkQ, srcHt) sinkRefs = popRefsOfHeight(sinkQ, sinkHt) return @@ -190,8 +190,8 @@ func popRefsOfHeight(q *types.RefByHeight, height uint64) (refs types.RefSlice) } func findCommon(taller, shorter *types.RefByHeight, height uint64) (tallRefs, comRefs types.RefSlice) { - d.Chk.True(tallestHeight(taller) == height) - d.Chk.True(tallestHeight(shorter) == height) + d.PanicIfFalse(tallestHeight(taller) == height) + d.PanicIfFalse(tallestHeight(shorter) == height) comIndices := []int{} // Walk through shorter and taller in tandem from the back (where the tallest Refs are). Refs from taller that go into a work queue are popped off directly, but doing so to shorter would mess up shortIdx. So, instead just keep track of the indices of common refs and drop them from shorter at the end. for shortIdx := shorter.Len() - 1; !taller.Empty() && tallestHeight(taller) == height; { @@ -229,7 +229,7 @@ func traverseSource(srcRef types.Ref, srcDB, sinkDB Database) traverseResult { srcBS := srcDB.validatingBatchStore() c := srcBS.Get(h) v := types.DecodeValue(c, srcDB) - d.Chk.True(v != nil, "Expected decoded chunk to be non-nil.") + d.PanicIfFalse(v != nil, "Expected decoded chunk to be non-nil.") sinkDB.validatingBatchStore().SchedulePut(c, srcRef.Height(), types.Hints{}) return traverseResult{h, v.Chunks(), len(c.Data())} } diff --git a/go/datas/remote_database_client.go b/go/datas/remote_database_client.go index c05ca58c09..db46f17f1b 100644 --- a/go/datas/remote_database_client.go +++ b/go/datas/remote_database_client.go @@ -22,7 +22,7 @@ func NewRemoteDatabase(baseURL, auth string) *RemoteDatabaseClient { func (rds *RemoteDatabaseClient) validatingBatchStore() (bs types.BatchStore) { bs = rds.ValueStore.BatchStore() - d.Chk.True(bs.IsValidating()) + d.PanicIfFalse(bs.IsValidating()) return } diff --git a/go/datas/serialize_hints.go b/go/datas/serialize_hints.go index 8a60f9c782..463ec43c3f 100644 --- a/go/datas/serialize_hints.go +++ b/go/datas/serialize_hints.go @@ -34,7 +34,7 @@ func serializeHash(w io.Writer, h hash.Hash) { digest := h.Digest() n, err := io.Copy(w, bytes.NewReader(digest[:])) d.Chk.NoError(err) - d.Chk.True(int64(hash.ByteLen) == n) + d.PanicIfFalse(int64(hash.ByteLen) == n) } func deserializeHints(reader io.Reader) types.Hints { @@ -65,6 +65,6 @@ func deserializeHash(reader io.Reader) hash.Hash { digest := hash.Digest{} n, err := io.ReadFull(reader, digest[:]) d.Chk.NoError(err) - d.Chk.True(int(hash.ByteLen) == n) + d.PanicIfFalse(int(hash.ByteLen) == n) return hash.New(digest) } diff --git a/go/dataset/dataset.go b/go/dataset/dataset.go index 1c68ebc747..2833da5fae 100644 --- a/go/dataset/dataset.go +++ b/go/dataset/dataset.go @@ -46,13 +46,13 @@ func (ds *Dataset) MaybeHeadRef() (types.Ref, bool) { // Head returns the current head Commit, which contains the current root of the Dataset's value tree. func (ds *Dataset) Head() types.Struct { c, ok := ds.MaybeHead() - d.Chk.True(ok, "Dataset \"%s\" does not exist", ds.id) + d.PanicIfFalse(ok, "Dataset \"%s\" does not exist", ds.id) return c } func (ds *Dataset) HeadRef() types.Ref { r, ok := ds.MaybeHeadRef() - d.Chk.True(ok, "Dataset \"%s\" does not exist", ds.id) + d.PanicIfFalse(ok, "Dataset \"%s\" does not exist", ds.id) return r } diff --git a/go/hash/hash.go b/go/hash/hash.go index 38aeaea10f..d4f10e99d9 100644 --- a/go/hash/hash.go +++ b/go/hash/hash.go @@ -95,7 +95,7 @@ func FromData(data []byte) Hash { // FromSlice creates a new Hash backed by data, ensuring that data is an acceptable length. func FromSlice(data []byte) Hash { - d.Chk.True(len(data) == ByteLen) + d.PanicIfFalse(len(data) == ByteLen) digest := Digest{} copy(digest[:], data) return New(digest) diff --git a/go/perf/codec-perf-rig/main.go b/go/perf/codec-perf-rig/main.go index 2fe34595d6..194be7dfc5 100644 --- a/go/perf/codec-perf-rig/main.go +++ b/go/perf/codec-perf-rig/main.go @@ -103,7 +103,7 @@ func main() { blob = ds.HeadValue().(types.Blob) outBytes, _ := ioutil.ReadAll(blob.Reader()) readDuration := time.Since(t1) - d.Chk.True(bytes.Compare(blobBytes, outBytes) == 0) + d.PanicIfFalse(bytes.Compare(blobBytes, outBytes) == 0) fmt.Printf("\t\t\t%s\t\t%s\n\n", rate(buildDuration, *blobSize), rate(readDuration, *blobSize)) } diff --git a/go/spec/ref_counting_ldb_store.go b/go/spec/ref_counting_ldb_store.go index 9d1b4ffa39..6eb2a42cac 100644 --- a/go/spec/ref_counting_ldb_store.go +++ b/go/spec/ref_counting_ldb_store.go @@ -24,7 +24,7 @@ func (r *refCountingLdbStore) AddRef() { } func (r *refCountingLdbStore) Close() (err error) { - d.Chk.True(r.refCount > 0) + d.PanicIfFalse(r.refCount > 0) r.refCount-- if r.refCount == 0 { err = r.LevelDBStore.Close() diff --git a/go/types/blob.go b/go/types/blob.go index 2e4a9a1cc5..7a1bc73523 100644 --- a/go/types/blob.go +++ b/go/types/blob.go @@ -39,8 +39,8 @@ func (b Blob) Splice(idx uint64, deleteCount uint64, data []byte) Blob { return b } - d.Chk.True(idx <= b.Len()) - d.Chk.True(idx+deleteCount <= b.Len()) + d.PanicIfFalse(idx <= b.Len()) + d.PanicIfFalse(idx+deleteCount <= b.Len()) cur := newCursorAtIndex(b.seq, idx) ch := newSequenceChunker(cur, b.seq.valueReader(), nil, makeBlobLeafChunkFn(b.seq.valueReader()), newIndexedMetaSequenceChunkFn(BlobKind, b.seq.valueReader()), hashValueByte) @@ -230,7 +230,7 @@ func NewStreamingBlob(r io.Reader, vrw ValueReadWriter) Blob { } } if err != nil { - d.Chk.True(io.EOF == err) + d.PanicIfFalse(io.EOF == err) if offset > 0 { makeChunk() } diff --git a/go/types/codec.go b/go/types/codec.go index edbeb41d77..5ab70f5257 100644 --- a/go/types/codec.go +++ b/go/types/codec.go @@ -33,13 +33,13 @@ func DecodeFromBytes(data []byte, vr ValueReader, tc *TypeCache) Value { br := &binaryNomsReader{data, 0} dec := newValueDecoder(br, vr, tc) v := dec.readValue() - d.Chk.True(br.pos() == uint32(len(data))) + d.PanicIfFalse(br.pos() == uint32(len(data))) return v } // DecodeValue decodes a value from a chunk source. It is an error to provide an empty chunk. func DecodeValue(c chunks.Chunk, vr ValueReader) Value { - d.Chk.False(c.IsEmpty()) + d.PanicIfTrue(c.IsEmpty()) v := DecodeFromBytes(c.Data(), vr, staticTypeCache) if cacher, ok := v.(hashCacher); ok { assignHash(cacher, c.Hash()) diff --git a/go/types/indexed_sequences.go b/go/types/indexed_sequences.go index 7e2963a157..4906dbfca7 100644 --- a/go/types/indexed_sequences.go +++ b/go/types/indexed_sequences.go @@ -71,7 +71,7 @@ func newCursorAtIndex(seq indexedSequence, idx uint64) *sequenceCursor { seq = cs.(indexedSequence) } - d.Chk.True(cur != nil) + d.PanicIfFalse(cur != nil) return cur } @@ -108,7 +108,7 @@ func newIndexedMetaSequenceChunkFn(kind NomsKind, source ValueReader) makeChunkF if kind == ListKind { col = newList(newListMetaSequence(tuples, source)) } else { - d.Chk.True(BlobKind == kind) + d.PanicIfFalse(BlobKind == kind) col = newBlob(newBlobMetaSequence(tuples, source)) } return col, orderedKeyFromSum(tuples), numLeaves diff --git a/go/types/list.go b/go/types/list.go index a2f40a856d..c9b1833434 100644 --- a/go/types/list.go +++ b/go/types/list.go @@ -109,7 +109,7 @@ func (l List) Type() *Type { // Get returns the value at the given index. If this list has been chunked then this will have to // descend into the prolly-tree which leads to Get being O(depth). func (l List) Get(idx uint64) Value { - d.Chk.True(idx < l.Len()) + d.PanicIfFalse(idx < l.Len()) cur := newCursorAtIndex(l.seq, idx) return cur.current().(Value) } @@ -140,7 +140,7 @@ func (l List) elemType() *Type { // Set returns a new list where the valie at the given index have been replaced with v. If idx is // out bounds then this panics. func (l List) Set(idx uint64, v Value) List { - d.Chk.True(idx < l.Len()) + d.PanicIfFalse(idx < l.Len()) return l.Splice(idx, 1, v) } @@ -157,8 +157,8 @@ func (l List) Splice(idx uint64, deleteCount uint64, vs ...Value) List { return l } - d.Chk.True(idx <= l.Len()) - d.Chk.True(idx+deleteCount <= l.Len()) + d.PanicIfFalse(idx <= l.Len()) + d.PanicIfFalse(idx+deleteCount <= l.Len()) cur := newCursorAtIndex(l.seq, idx) ch := newSequenceChunker(cur, l.seq.valueReader(), nil, makeListLeafChunkFn(l.seq.valueReader()), newIndexedMetaSequenceChunkFn(ListKind, l.seq.valueReader()), hashValueBytes) @@ -181,7 +181,7 @@ func (l List) Insert(idx uint64, vs ...Value) List { // Remove returns a new list where the items at index start (inclusive) through end (exclusive) have // been removed. This panics if end is smaller than start. func (l List) Remove(start uint64, end uint64) List { - d.Chk.True(start <= end) + d.PanicIfFalse(start <= end) return l.Splice(start, end-start) } diff --git a/go/types/list_iterator.go b/go/types/list_iterator.go index 4932b164af..ab22ccb4bf 100644 --- a/go/types/list_iterator.go +++ b/go/types/list_iterator.go @@ -16,7 +16,7 @@ type ListIterator struct { // Next returns subsequent Values from a List, starting with the index at which the iterator was // created. If there are no more Values, Next() returns nil. func (li ListIterator) Next() (out Value) { - d.Chk.True(li.cursor != nil, "Cannot use a nil ListIterator") + d.PanicIfFalse(li.cursor != nil, "Cannot use a nil ListIterator") if li.cursor.valid() { out = li.cursor.current().(Value) li.cursor.advance() diff --git a/go/types/map.go b/go/types/map.go index 1a94eaf5d3..7d71263287 100644 --- a/go/types/map.go +++ b/go/types/map.go @@ -53,7 +53,7 @@ func NewStreamingMap(vrw ValueReadWriter, kvs <-chan Value) <-chan Map { k = nil } - d.Chk.True(k == nil) + d.PanicIfFalse(k == nil) outChan <- mx.Finish() }() return outChan @@ -162,7 +162,7 @@ func (m Map) SetM(kv ...Value) Map { if len(kv) == 0 { return m } - d.Chk.True(len(kv)%2 == 0) + d.PanicIfFalse(len(kv)%2 == 0) k, v, tail := kv[0], kv[1], kv[2:] @@ -253,7 +253,7 @@ func buildMapData(values []Value) mapEntrySlice { } // Sadly, d.Chk.Equals() costs too much. BUG #83 - d.Chk.True(0 == len(values)%2, "Must specify even number of key/value pairs") + d.PanicIfFalse(0 == len(values)%2, "Must specify even number of key/value pairs") kvs := make(mapEntrySlice, len(values)/2) for i := 0; i < len(values); i += 2 { diff --git a/go/types/mapMutator.go b/go/types/mapMutator.go index d8be3d6721..4c31d89340 100644 --- a/go/types/mapMutator.go +++ b/go/types/mapMutator.go @@ -16,13 +16,13 @@ func newMapMutator(vrw ValueReadWriter) *mapMutator { } func (mx *mapMutator) Set(key Value, val Value) *mapMutator { - d.Chk.True(mx.oc != nil, "Can't call Set() again after Finish()") + d.PanicIfFalse(mx.oc != nil, "Can't call Set() again after Finish()") mx.oc.MapSet(key, val) return mx } func (mx *mapMutator) Finish() Map { - d.Chk.True(mx.oc != nil, "Can only call Finish() once") + d.PanicIfFalse(mx.oc != nil, "Can only call Finish() once") defer func() { mx.oc = nil }() diff --git a/go/types/meta_sequence.go b/go/types/meta_sequence.go index dad5b96add..31d4630be3 100644 --- a/go/types/meta_sequence.go +++ b/go/types/meta_sequence.go @@ -25,7 +25,7 @@ type metaSequence interface { } func newMetaTuple(ref Ref, key orderedKey, numLeaves uint64, child Collection) metaTuple { - d.Chk.True(Ref{} != ref) + d.PanicIfFalse(Ref{} != ref) return metaTuple{ref, key, numLeaves, child} } @@ -85,7 +85,7 @@ func (key orderedKey) Less(mk2 orderedKey) bool { case mk2.isOrderedByValue: return false default: - d.Chk.False(key.h.IsEmpty() || mk2.h.IsEmpty()) + d.PanicIfTrue(key.h.IsEmpty() || mk2.h.IsEmpty()) return key.h.Less(mk2.h) } } @@ -225,7 +225,7 @@ func readMetaTupleValue(item sequenceItem, vr ValueReader) Value { } r := mt.ref.TargetHash() - d.Chk.False(r.IsEmpty()) + d.PanicIfTrue(r.IsEmpty()) return vr.ReadValue(r) } @@ -234,7 +234,7 @@ func metaHashValueBytes(item sequenceItem, rv *rollingValueHasher) { v := mt.key.v if !mt.key.isOrderedByValue { // See https://github.com/attic-labs/noms/issues/1688#issuecomment-227528987 - d.Chk.False(mt.key.h.IsEmpty()) + d.PanicIfTrue(mt.key.h.IsEmpty()) v = constructRef(MakeRefType(BoolType), mt.key.h, 0) } diff --git a/go/types/opcache_compare.go b/go/types/opcache_compare.go index 98770e61d6..52cc2f5ff6 100644 --- a/go/types/opcache_compare.go +++ b/go/types/opcache_compare.go @@ -29,9 +29,9 @@ func (opCacheComparer) Compare(a, b []byte) int { return 1 } a, b = a[1:], b[1:] - d.Chk.True(len(a) == hash.ByteLen && len(b) == hash.ByteLen) + d.PanicIfFalse(len(a) == hash.ByteLen && len(b) == hash.ByteLen) res := bytes.Compare(a, b) - d.Chk.True(res != 0 || aKind == bKind) + d.PanicIfFalse(res != 0 || aKind == bKind) return res case BoolKind: return bytes.Compare(a, b) diff --git a/go/types/ordered_sequences.go b/go/types/ordered_sequences.go index f564c8b9ca..6b20e422c1 100644 --- a/go/types/ordered_sequences.go +++ b/go/types/ordered_sequences.go @@ -94,7 +94,7 @@ func newCursorAt(seq orderedSequence, key orderedKey, forInsertion bool, last bo seq = cs.(orderedSequence) } - d.Chk.True(cur != nil) + d.PanicIfFalse(cur != nil) return cur } @@ -107,7 +107,7 @@ func seekTo(cur *sequenceCursor, key orderedKey, lastPositionIfNotFound bool) bo }) if cur.idx == seq.seqLen() && lastPositionIfNotFound { - d.Chk.True(cur.idx > 0) + d.PanicIfFalse(cur.idx > 0) cur.idx-- } @@ -117,7 +117,7 @@ func seekTo(cur *sequenceCursor, key orderedKey, lastPositionIfNotFound bool) bo // Gets the key used for ordering the sequence at current index. func getCurrentKey(cur *sequenceCursor) orderedKey { seq, ok := cur.seq.(orderedSequence) - d.Chk.True(ok, "need an ordered sequence here") + d.PanicIfFalse(ok, "need an ordered sequence here") return seq.getKey(cur.idx) } @@ -138,7 +138,7 @@ func newOrderedMetaSequenceChunkFn(kind NomsKind, vr ValueReader) makeChunkFn { if kind == SetKind { col = newSet(newSetMetaSequence(tuples, vr)) } else { - d.Chk.True(MapKind == kind) + d.PanicIfFalse(MapKind == kind) col = newMap(newMapMetaSequence(tuples, vr)) } return col, tuples.last().key, numLeaves diff --git a/go/types/ordered_sequences_diff.go b/go/types/ordered_sequences_diff.go index 58b022dfed..7e12b228e8 100644 --- a/go/types/ordered_sequences_diff.go +++ b/go/types/ordered_sequences_diff.go @@ -229,8 +229,8 @@ func syncWithIdx(cur *sequenceCursor, hasMore bool, allowPastEnd bool) { * Returns an array matching |a| and |b| respectively to whether that cursor has more values. */ func doFastForward(allowPastEnd bool, a *sequenceCursor, b *sequenceCursor) (aHasMore bool, bHasMore bool) { - d.Chk.True(a.valid()) - d.Chk.True(b.valid()) + d.PanicIfFalse(a.valid()) + d.PanicIfFalse(b.valid()) aHasMore = true bHasMore = true diff --git a/go/types/path.go b/go/types/path.go index 50e0a2a161..1c0e2e109c 100644 --- a/go/types/path.go +++ b/go/types/path.go @@ -162,7 +162,7 @@ func NewIndexIntoKeyPath(idx Value) IndexPath { func newIndexPath(idx Value, intoKey bool) IndexPath { k := idx.Type().Kind() - d.Chk.True(k == StringKind || k == BoolKind || k == NumberKind) + d.PanicIfFalse(k == StringKind || k == BoolKind || k == NumberKind) return IndexPath{idx, intoKey} } @@ -221,7 +221,7 @@ func NewHashIndexIntoKeyPath(h hash.Hash) HashIndexPath { } func newHashIndexPath(h hash.Hash, intoKey bool) HashIndexPath { - d.Chk.False(h.IsEmpty()) + d.PanicIfTrue(h.IsEmpty()) return HashIndexPath{h, intoKey} } diff --git a/go/types/ref.go b/go/types/ref.go index 3df3627646..0fab84dd4f 100644 --- a/go/types/ref.go +++ b/go/types/ref.go @@ -22,8 +22,8 @@ func NewRef(v Value) Ref { // Constructs a Ref directly from struct properties. This should not be used outside decoding and testing within the types package. func constructRef(t *Type, target hash.Hash, height uint64) Ref { - d.Chk.True(RefKind == t.Kind()) - d.Chk.True(ValueType != t.Desc.(CompoundDesc).ElemTypes[0]) + d.PanicIfFalse(RefKind == t.Kind()) + d.PanicIfFalse(ValueType != t.Desc.(CompoundDesc).ElemTypes[0]) return Ref{target, height, t, &hash.Hash{}} } diff --git a/go/types/sequence_chunker.go b/go/types/sequence_chunker.go index c01fdf83c7..ac6b75dec6 100644 --- a/go/types/sequence_chunker.go +++ b/go/types/sequence_chunker.go @@ -30,9 +30,9 @@ func newEmptySequenceChunker(vr ValueReader, vw ValueWriter, makeChunk, parentMa func newSequenceChunker(cur *sequenceCursor, vr ValueReader, vw ValueWriter, makeChunk, parentMakeChunk makeChunkFn, hashValueBytes hashValueBytesFn) *sequenceChunker { // |cur| will be nil if this is a new sequence, implying this is a new tree, or the tree has grown in height relative to its original chunked form. - d.Chk.True(makeChunk != nil) - d.Chk.True(parentMakeChunk != nil) - d.Chk.True(hashValueBytes != nil) + d.PanicIfFalse(makeChunk != nil) + d.PanicIfFalse(parentMakeChunk != nil) + d.PanicIfFalse(hashValueBytes != nil) sc := &sequenceChunker{ cur, @@ -129,7 +129,7 @@ func (sc *sequenceChunker) resume() { } func (sc *sequenceChunker) Append(item sequenceItem) { - d.Chk.True(item != nil) + d.PanicIfFalse(item != nil) sc.current = append(sc.current, item) sc.rv.ClearLastBoundary() sc.hashValueBytes(item, sc.rv) @@ -152,7 +152,7 @@ func (sc *sequenceChunker) skipParentIfExists() { } func (sc *sequenceChunker) createParent() { - d.Chk.True(sc.parent == nil) + d.PanicIfFalse(sc.parent == nil) var parent *sequenceCursor if sc.cur != nil && sc.cur.parent != nil { // Clone the parent cursor because otherwise calling cur.advance() will affect our parent - and vice versa - in surprising ways. Instead, Skip moves forward our parent's cursor if we advance across a boundary. @@ -204,7 +204,7 @@ func (sc *sequenceChunker) anyPending() bool { // Returns the root sequence of the resulting tree. The logic here is subtle, but hopefully correct and understandable. See comments inline. func (sc *sequenceChunker) Done() sequence { - d.Chk.False(sc.done) + d.PanicIfTrue(sc.done) sc.done = true if sc.cur != nil { @@ -232,7 +232,7 @@ func (sc *sequenceChunker) Done() sequence { } // (3) This is an internal node of the tree which contains a single reference to a child node. This can occur if a non-leaf chunker happens to chunk on the first item (metaTuple) appended. In this case, this is the root of the tree, but it is *not* canonical and we must walk down until we find cases (1) or (2), above. - d.Chk.True(!sc.isLeaf && len(sc.current) == 1) + d.PanicIfFalse(!sc.isLeaf && len(sc.current) == 1) mt := sc.current[0].(metaTuple) for { diff --git a/go/types/sequence_cursor.go b/go/types/sequence_cursor.go index f2416c78df..25bd5c6620 100644 --- a/go/types/sequence_cursor.go +++ b/go/types/sequence_cursor.go @@ -16,7 +16,7 @@ type sequenceCursor struct { func newSequenceCursor(parent *sequenceCursor, seq sequence, idx int) *sequenceCursor { if idx < 0 { idx += seq.seqLen() - d.Chk.True(idx >= 0) + d.PanicIfFalse(idx >= 0) } return &sequenceCursor{parent, seq, idx} @@ -31,7 +31,7 @@ func (cur *sequenceCursor) getItem(idx int) sequenceItem { } func (cur *sequenceCursor) sync() { - d.Chk.True(cur.parent != nil) + d.PanicIfFalse(cur.parent != nil) cur.seq = cur.parent.getChildSequence() } @@ -44,7 +44,7 @@ func (cur *sequenceCursor) getChildSequence() sequence { // Returns the value the cursor refers to. Fails an assertion if the cursor doesn't point to a value. func (cur *sequenceCursor) current() sequenceItem { - d.Chk.True(cur.valid()) + d.PanicIfFalse(cur.valid()) return cur.getItem(cur.idx) } @@ -98,7 +98,7 @@ func (cur *sequenceCursor) retreatMaybeAllowBeforeStart(allowBeforeStart bool) b if cur.idx == -1 { return false } - d.Chk.True(0 == cur.idx) + d.PanicIfFalse(0 == cur.idx) if cur.parent != nil && cur.parent.retreatMaybeAllowBeforeStart(false) { cur.sync() cur.idx = cur.length() - 1 diff --git a/go/types/setMutator.go b/go/types/setMutator.go index 202dda093c..c7e8af1b0d 100644 --- a/go/types/setMutator.go +++ b/go/types/setMutator.go @@ -16,13 +16,13 @@ func newSetMutator(vrw ValueReadWriter) *setMutator { } func (mx *setMutator) Insert(val Value) *setMutator { - d.Chk.True(mx.oc != nil, "Can't call Insert() again after Finish()") + d.PanicIfFalse(mx.oc != nil, "Can't call Insert() again after Finish()") mx.oc.SetInsert(val) return mx } func (mx *setMutator) Finish() Set { - d.Chk.True(mx.oc != nil, "Can only call Finish() once") + d.PanicIfFalse(mx.oc != nil, "Can only call Finish() once") defer func() { mx.oc = nil }() diff --git a/go/types/struct.go b/go/types/struct.go index 3223e9d9fa..179b179fe9 100644 --- a/go/types/struct.go +++ b/go/types/struct.go @@ -47,7 +47,7 @@ func NewStruct(name string, data StructData) Struct { func NewStructWithType(t *Type, data ValueSlice) Struct { desc := t.Desc.(StructDesc) - d.Chk.True(len(data) == len(desc.fields)) + d.PanicIfFalse(len(data) == len(desc.fields)) for i, field := range desc.fields { v := data[i] assertSubtype(field.t, v) diff --git a/go/types/type_cache.go b/go/types/type_cache.go index f09a2373aa..08bdfbe963 100644 --- a/go/types/type_cache.go +++ b/go/types/type_cache.go @@ -77,7 +77,7 @@ func (tc *TypeCache) getCompoundType(kind NomsKind, elemTypes ...*Type) *Type { } func (tc *TypeCache) makeStructType(name string, fieldNames []string, fieldTypes []*Type) *Type { - d.Chk.True(len(fieldNames) == len(fieldTypes), "len(fieldNames) != len(fieldTypes)") + d.PanicIfFalse(len(fieldNames) == len(fieldTypes), "len(fieldNames) != len(fieldTypes)") verifyStructName(name) verifyFieldNames(fieldNames) diff --git a/go/types/value_decoder.go b/go/types/value_decoder.go index 1b05221ffe..d6690367cf 100644 --- a/go/types/value_decoder.go +++ b/go/types/value_decoder.go @@ -51,7 +51,7 @@ func (r *valueDecoder) readType() *Type { return r.tc.getCycleType(r.readUint32()) } - d.Chk.True(IsPrimitiveKind(k)) + d.PanicIfFalse(IsPrimitiveKind(k)) return MakePrimitiveType(k) } diff --git a/go/types/value_encoder.go b/go/types/value_encoder.go index 8d5b7d97ae..62e235539c 100644 --- a/go/types/value_encoder.go +++ b/go/types/value_encoder.go @@ -50,7 +50,7 @@ func (w *valueEncoder) writeType(t *Type, parentStructTypes []*Type) { w.writeCycle(uint32(t.Desc.(CycleDesc))) default: w.writeKind(k) - d.Chk.True(IsPrimitiveKind(k)) + d.PanicIfFalse(IsPrimitiveKind(k)) } } @@ -106,7 +106,7 @@ func (w *valueEncoder) maybeWriteMetaSequence(seq sequence) bool { v := tuple.key.v if !tuple.key.isOrderedByValue { // See https://github.com/attic-labs/noms/issues/1688#issuecomment-227528987 - d.Chk.False(tuple.key.h.IsEmpty()) + d.PanicIfTrue(tuple.key.h.IsEmpty()) v = constructRef(MakeRefType(BoolType), tuple.key.h, 0) } w.writeValue(v) diff --git a/go/types/value_store.go b/go/types/value_store.go index 20568ed36c..3d41673442 100644 --- a/go/types/value_store.go +++ b/go/types/value_store.go @@ -105,10 +105,10 @@ func (lvs *ValueStore) ReadValue(r hash.Hash) Value { // WriteValue takes a Value, schedules it to be written it to lvs, and returns an appropriately-typed types.Ref. v is not guaranteed to be actually written until after Flush(). func (lvs *ValueStore) WriteValue(v Value) Ref { - d.Chk.True(v != nil) + d.PanicIfFalse(v != nil) // Encoding v causes any child chunks, e.g. internal nodes if v is a meta sequence, to get written. That needs to happen before we try to validate v. c := EncodeValue(v, lvs) - d.Chk.False(c.IsEmpty()) + d.PanicIfTrue(c.IsEmpty()) hash := c.Hash() height := maxChunkHeight(v) + 1 r := constructRef(MakeRefType(v.Type()), hash, height) @@ -217,7 +217,7 @@ func (lvs *ValueStore) checkChunksInCache(v Value, readValues bool) Hints { func getTargetType(refBase Ref) *Type { refType := refBase.Type() - d.Chk.True(RefKind == refType.Kind()) + d.PanicIfFalse(RefKind == refType.Kind()) return refType.Desc.(CompoundDesc).ElemTypes[0] } diff --git a/go/util/orderedparallel/ordered_parallel.go b/go/util/orderedparallel/ordered_parallel.go index d97d407b77..494bde5894 100644 --- a/go/util/orderedparallel/ordered_parallel.go +++ b/go/util/orderedparallel/ordered_parallel.go @@ -15,7 +15,7 @@ type ProcessFn func(in interface{}) (out interface{}) // Creates a pool of |parallelism| goroutines to process values off of |input| by calling |fn| and guarantees that results of each call will be sent on |out| in the order the corresponding input was received. func New(input chan interface{}, fn ProcessFn, parallelism int) chan interface{} { - d.Chk.True(parallelism > 0) + d.PanicIfFalse(parallelism > 0) mu := &sync.Mutex{} inCount := uint(0) diff --git a/go/util/sizecache/size_cache.go b/go/util/sizecache/size_cache.go index 389fca3f0b..7b4739a34e 100644 --- a/go/util/sizecache/size_cache.go +++ b/go/util/sizecache/size_cache.go @@ -67,7 +67,7 @@ func (c *SizeCache) Add(key interface{}, size uint64, value interface{}) { for el := c.lru.Front(); el != nil && c.totalSize > c.maxSize; { key1 := el.Value ce, ok := c.cache[key1] - d.Chk.True(ok, "SizeCache is missing expected value") + d.PanicIfFalse(ok, "SizeCache is missing expected value") next := el.Next() delete(c.cache, key1) c.totalSize -= ce.size diff --git a/go/walk/walk.go b/go/walk/walk.go index 6c072e689d..c9a0648837 100644 --- a/go/walk/walk.go +++ b/go/walk/walk.go @@ -148,7 +148,7 @@ func SomeChunksP(r types.Ref, bs types.BatchStore, stopCb SomeChunksStopCallback if chunkCb != nil || r.Height() > 1 { c = bs.Get(tr) - d.Chk.False(c.IsEmpty()) + d.PanicIfTrue(c.IsEmpty()) if chunkCb != nil { chunkCb(r, c) @@ -200,7 +200,7 @@ func newRefQueue() refQueue { } pop := func() types.Ref { - d.Chk.True(len(buff) > 0) + d.PanicIfFalse(len(buff) > 0) r := buff[0] buff = buff[1:] return r @@ -223,7 +223,7 @@ func newRefQueue() refQueue { push(r) case head <- first: r := pop() - d.Chk.True(r == first) + d.PanicIfFalse(r == first) case <-done: break loop } diff --git a/samples/go/csv/read.go b/samples/go/csv/read.go index 86214fead8..19e3f1782a 100644 --- a/samples/go/csv/read.go +++ b/samples/go/csv/read.go @@ -55,7 +55,7 @@ func EscapeStructFieldFromCSV(input string) string { // MakeStructTypeFromHeaders creates a struct type from the headers using |kinds| as the type of each field. If |kinds| is empty, default to strings. func MakeStructTypeFromHeaders(headers []string, structName string, kinds KindSlice) (typ *types.Type, fieldOrder []int, kindMap []types.NomsKind) { useStringType := len(kinds) == 0 - d.Chk.True(useStringType || len(headers) == len(kinds)) + d.PanicIfFalse(useStringType || len(headers) == len(kinds)) fieldMap := make(types.TypeMap, len(headers)) origOrder := make(map[string]int, len(headers)) diff --git a/samples/go/demo-server/main.go b/samples/go/demo-server/main.go index a9ec8636d2..80049a14af 100644 --- a/samples/go/demo-server/main.go +++ b/samples/go/demo-server/main.go @@ -57,7 +57,7 @@ type cachingReadThroughStoreFactory struct { } func (f *cachingReadThroughStoreFactory) CreateStore(ns string) chunks.ChunkStore { - d.Chk.True(f.factory != nil, "Cannot use cachingReadThroughStoreFactory after Shutter().") + d.PanicIfFalse(f.factory != nil, "Cannot use cachingReadThroughStoreFactory after Shutter().") return chunks.NewReadThroughStore(f.cache, f.factory.CreateStore(ns)) } diff --git a/samples/go/nomsfs/nomsfs.go b/samples/go/nomsfs/nomsfs.go index 5ea2807d8d..8237575c28 100644 --- a/samples/go/nomsfs/nomsfs.go +++ b/samples/go/nomsfs/nomsfs.go @@ -443,7 +443,7 @@ func (nfile nomsFile) Write(data []byte, off int64) (uint32, fuse.Status) { ll := uint64(blob.Len()) oo := uint64(off) - d.Chk.True(ll >= oo) + d.PanicIfFalse(ll >= oo) del := uint64(len(data)) if ll-oo < del { del = ll - oo diff --git a/tools/file/file.go b/tools/file/file.go index 80685290e1..bf156acde5 100644 --- a/tools/file/file.go +++ b/tools/file/file.go @@ -34,6 +34,6 @@ func DumbCopy(srcPath, dstPath string) { // MyDir returns the directory in which the file containing the calling source code resides. func MyDir() string { _, path, _, ok := runtime.Caller(1) - d.Chk.True(ok, "Should have been able to get Caller.") + d.PanicIfFalse(ok, "Should have been able to get Caller.") return filepath.Dir(path) }