mirror of
https://github.com/hanzoai/graph.git
synced 2026-10-30 18:35:37 +00:00
Derived from Dgraph (github.com/dgraph-io/dgraph) at commit 64804bd2, Apache-2.0. See NOTICE. WHAT THIS IS. The graph engine as a Go library: posting lists, the DQL parser, the type and tokenizer system, the index and schema layers, and the wire types. 39,170 lines of the upstream's 166,337. THE STORE is github.com/luxfi/zapdb, a Badger fork that kept the package name, the subpackages (options, pb, y) and the API — Open, OpenManaged, DB, Options — so the 74 import sites are aliased rather than rewritten. THE CODEC is ZAP. zapdb serializes with ZAP, not protobuf: its pb package builds the ZAP types by default and the protobuf ones only under `-tags grpc`, a path that does not compile (table/builder.go calls pb.Marshal, which that tag removes). One call site in posting needed converting; every other type here is Hanzo's own protobuf and is untouched. NO TRANSPORT. An embedded engine dials nothing, so nothing here imports google.golang.org/grpc. Removed: 20 transport functions in x, the generated service stubs for Raft, Zero and Worker (1,657 lines), and the JWT helper — identity belongs to IAM. The core called none of them. NOT KEPT: worker, conn, raftwal, the cluster commands, the GraphQL layer and the test harnesses. `query`, the DQL execution engine, went with them because it depends on worker; parsing DQL is available here, executing it is not. The history of the upstream project lives at github.com/dgraph-io/dgraph. This repository begins at the derivation because three quarters of that history describes code this fork does not carry.
107 lines
2.6 KiB
Go
107 lines
2.6 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package x
|
|
|
|
// This file contains some functions for error handling. Note that we are moving
|
|
// towards using x.Trace, i.e., rpc tracing using net/tracer. But for now, these
|
|
// functions are useful for simple checks logged on one machine.
|
|
// Some common use cases are:
|
|
// (1) You receive an error from external lib, and would like to check/log fatal.
|
|
// For this, use x.Check, x.Checkf. These will check for err != nil, which is
|
|
// more common in Go. If you want to check for boolean being true, use
|
|
// x.Assert, x.Assertf.
|
|
// (2) You receive an error from external lib, and would like to pass on with some
|
|
// stack trace information. In this case, use x.Wrap or errors.Wrapf.
|
|
// (3) You want to generate a new error with stack trace info. Use errors.Errorf.
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Check logs fatal if err != nil.
|
|
func Check(err error) {
|
|
if err != nil {
|
|
err = errors.Wrap(err, "")
|
|
log.Fatalf("%+v", err)
|
|
}
|
|
}
|
|
|
|
// Checkf is Check with extra info.
|
|
func Checkf(err error, format string, args ...interface{}) {
|
|
if err != nil {
|
|
err = errors.Wrapf(err, format, args...)
|
|
log.Fatalf("%+v", err)
|
|
}
|
|
}
|
|
|
|
// CheckfNoTrace is Checkf without a stack trace.
|
|
func CheckfNoTrace(err error) {
|
|
if err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
}
|
|
|
|
// CheckfNoLog exits on error without any message (to avoid duplicate error messages).
|
|
func CheckfNoLog(err error) {
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
// Check2 acts as convenience wrapper around Check, using the 2nd argument as error.
|
|
func Check2(_ interface{}, err error) {
|
|
Check(err)
|
|
}
|
|
|
|
// Panic on error.
|
|
func Panic(err error) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func Log(err error, msg string) {
|
|
if err != nil {
|
|
log.Printf("%s Error: %v\n", msg, err)
|
|
}
|
|
}
|
|
|
|
// Ignore function is used to ignore errors deliberately, while keeping the
|
|
// linter happy.
|
|
func Ignore(_ error) {
|
|
// Do nothing.
|
|
}
|
|
|
|
// AssertTrue asserts that b is true. Otherwise, it would log fatal.
|
|
func AssertTrue(b bool) {
|
|
if !b {
|
|
log.Fatalf("%+v", errors.Errorf("Assert failed"))
|
|
}
|
|
}
|
|
|
|
// AssertTruef is AssertTrue with extra info.
|
|
func AssertTruef(b bool, format string, args ...interface{}) {
|
|
if !b {
|
|
log.Fatalf("%+v", errors.Errorf(format, args...))
|
|
}
|
|
}
|
|
|
|
// AssertTruefNoTrace is AssertTruef without a stack trace.
|
|
func AssertTruefNoTrace(b bool, format string, args ...interface{}) {
|
|
if !b {
|
|
log.Fatalf("%+v", fmt.Errorf(format, args...))
|
|
}
|
|
}
|
|
|
|
// Fatalf logs fatal.
|
|
func Fatalf(format string, args ...interface{}) {
|
|
log.Fatalf("%+v", errors.Errorf(format, args...))
|
|
}
|