Skip to content

Checks and errors ​

checks in circuit.ts turns on Circuit's built-in checks and adds your own. circuit validate runs them all.

Built-in checks ​

CheckMakes sure that
untrusted_vlansA VLAN marked untrusted: true only gets an address on your filtering_devices.
exports_end_in_rejectEvery BGP export ends with a rule that rejects everything else. Customers are left out.
imports_end_in_accept_or_rejectEvery BGP import ends with a rule that decides for every route.
native_vlans_are_dead_endsA native VLAN is native on at most one trunk per device, and no other port there carries it.
tunnels_outside_offeredA tunnel's own address isn't inside what you announce over it.
same_vlan_idsOne VLAN name has the same ID on every device.

Your own checks ​

Any other name in checks takes a function that gets the network and returns what it found. This one is from the edge router example, where circuit.ts turns it on with checks: { imports_filtered: importsFiltered }:

ts
// This network's own checks, beside Circuit's built-in ones. circuit.ts turns them on in `checks`.

import type { Check } from "circuit";

/** Every BGP neighbor has an import policy. Without one, the router accepts no route from it. */
export const importsFiltered: Check = (network) =>
    network.devices.flatMap((device) =>
        Object.entries(device.routing?.bgp?.neighbors ?? {})
            .filter(([, neighbor]) => !neighbor.import_policy)
            .map(([name]) => ({
                device: device.name,
                path: `routing.bgp.neighbors.${name}`,
                message: "has no import_policy, so the router accepts no route from it. Write one.",
            }))
    );
  • Your check sees each device as the device runs it, with its parts merged in. Each call, { communities } rule, interface set, and management.allow is replaced by what it stands for. Each neighbor holds what it takes from its group.
  • It gets a copy, so it can't change anything.
  • Return device and path with the message, and Circuit shows the file and line.
  • For IP math, use the global address: .contains(outer, inner), .overlaps(a, b), .family(x), .host(x), .first(x), and .last(x).

Only files in lib/ import from Circuit, and only types.

What validate tells you ​

Your editor catches most mistakes as you type. circuit validate catches the rest, with the file and line:

sites/site-a/switch-01.ts:32: switch-01: switching.stp.mod: no such field. Did you mean mode?
tenants/tenant-a.ts:21: switch-01: interfaces.ethernet.10g-5.descripton: no such field. Did you mean description?

It stops on:

  • an unknown key, or a name the device doesn't have
  • a port the device's model doesn't have
  • a link that doesn't link back
  • one value written twice with two different values
  • an ordered list written in two places, or rules that no device places
  • a device file with no device, or with two
  • the same hostname twice
  • a site with no device, or a part for a hostname that isn't a device
  • untrusted: true while its check is off

It warns and goes on when a linked port's description doesn't give the device and port at the other end.

Where the editor falls short ​

  • Only circuit validate catches a typo in a key inside a part's map, such as a port in a tenant file.
  • address_sets: merge([a, b]) in a device file hides those names from the editor, so it shows false errors. Write the map out, or bring it in with include.
  • For const two = merge([rule_a, rule_b]), the editor says then is written twice. Write part("filter", [rule_a, rule_b]) instead.
  • bgpNeighbors() is a whole set. Merged with other addresses, it adds nothing.

Released under the Business Source License 1.1.