You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: errors.go
    path of file: ./repos/cockroach/pkg/ccl/changefeedccl/changefeedbase
    
    the code of the file until where you have to start completion: // Copyright 2019 The Cockroach Authors.
//
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
//     https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt

package changefeedbase

import (
	"context"

	"github.com/cockroachdb/cockroach/pkg/jobs"
	"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
	"github.com/cockroachdb/errors"
)

// FailureType is the reason for the changefeed failure that maps to the
// failure_type values we emit in the Changefe
    
func AsTerminalError(ctx context.Context, dh drainHelper, cause error) (termErr error) {
	if cause == nil {
		return nil
	}

	if err := ctx.Err(); err != nil {
		// If context has been cancelled, we must respect that; this happens
		// if, e.g. this changefeed is being cancelled.
		return err
	}

	if dh.IsDraining() {
		// This node is being drained. It's safe to propagate this error (to the
		// job registry) since job registry should not be able to commit this error
		// to the jobs table; but to be safe, make sure this error is marked as jobs
		// retryable error to ensure that some other node retries this changefeed.
		return jobs.MarkAsRetryJobError(cause)
	}

	// GC TTL errors are always fatal.
	if errors.HasType(cause, (*kvpb.BatchTimestampBeforeGCError)(nil)) {
		return WithTerminalError(cause)
	}

	// Explicitly marked terminal errors are terminal.
	if errors.Is(cause, &terminalError{}) {
		return cause
	}

	// Assertion failures are terminal.
	if errors.HasAssertionFailure(cause) {
		return cause
	}

	// All other errors retry.
	return nil
}