{"record":{"id":"281db234a4003aa3","repo":"slackhq/nebula","slug":"errinitiatenotcalled","errorCode":"ErrInitiateNotCalled","errorMessage":"initiate must be called before ProcessPacket for initiators","messagePattern":"initiate must be called before ProcessPacket for initiators","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"handshake/errors.go","lineNumber":8,"sourceCode":"package handshake\n\nimport \"errors\"\n\nvar (\n\tErrInitiateOnResponder     = errors.New(\"initiate called on responder\")\n\tErrInitiateAlreadyCalled   = errors.New(\"initiate already called\")\n\tErrInitiateNotCalled       = errors.New(\"initiate must be called before ProcessPacket for initiators\")\n\tErrPacketTooShort          = errors.New(\"packet too short\")\n\tErrPublicKeyMismatch       = errors.New(\"public key mismatch between certificate and handshake\")\n\tErrIncompleteHandshake     = errors.New(\"handshake completed without receiving required content\")\n\tErrMachineFailed           = errors.New(\"handshake machine has failed\")\n\tErrUnknownSubtype          = errors.New(\"unknown handshake subtype\")\n\tErrMissingContent          = errors.New(\"expected handshake content but message was empty\")\n\tErrUnexpectedContent       = errors.New(\"received unexpected handshake content\")\n\tErrInvalidRemoteIndex      = errors.New(\"peer sent an invalid index in handshake payload\")\n\tErrIndexAllocation         = errors.New(\"failed to allocate local index\")\n\tErrNoCredential            = errors.New(\"no handshake credential available for cert version\")\n\tErrAsymmetricCipherKeys    = errors.New(\"noise produced only one cipher key\")\n\tErrMultiMessageUnsupported = errors.New(\"multi-message handshake patterns are not yet supported by the manager\")\n\tErrSubtypeMismatch         = errors.New(\"packet subtype does not match handshake machine subtype\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/handshake/errors.go#L1-L23","documentation":"ErrInitiateNotCalled is returned by Machine.ProcessPacket when the machine is an initiator but its handshake state is still at message index 0, meaning Initiate() was never called. An initiator must send the first handshake message before it can process any packet.","triggerScenarios":"Calling ProcessPacket on an initiator Machine before ever calling Initiate, as in handshake/machine.go:220 (m.result.Initiator && m.hs.MessageIndex() == 0).","commonSituations":"Event-driven code that starts reading from the socket before sending the initiation message; wiring where incoming packets reach the machine before Initiate is invoked; tests feeding a packet to a fresh initiator.","solutions":["Call m.Initiate(payload) first and send the returned packet before processing any incoming packets.","Reorder startup logic so Initiate is guaranteed to run before the read loop calls ProcessPacket.","Verify the machine was constructed with the intended initiator flag."],"exampleFix":"// before\npacket := make([]byte, 100)\nmsg, _, err := m.ProcessPacket(nil, packet) // initiate never called\n// after\ninitPacket, err := m.Initiate(nil)\nconn.Write(initPacket)\nmsg, _, err := m.ProcessPacket(nil, packet)","handlingStrategy":"try-catch","validationCode":"if m.result.Initiator && !initiated {\n    return errors.New(\"call Initiate before ProcessPacket\")\n}","typeGuard":"func readyToProcess(m *handshake.Machine) bool {\n    r := m.Result()\n    return !m.Failed() && (!r.Initiator || initiatedFlag)\n}","tryCatchPattern":"msg, packet, err := m.ProcessPacket(h, buf)\nif errors.Is(err, handshake.ErrInitiateNotCalled) {\n    // must initiate first: build and send init packet before processing\n}","preventionTips":["Always run Initiate and send its packet before starting the read loop","Sequence startup: initiate → write → then process incoming packets","Initialize machines and handshakes in one place to enforce ordering","Add tests that exercise the full initiator flow before processing"],"tags":["handshake","state-machine","ordering"],"backgroundTag":"invalid-state-transition","analyzedSha":"dd8f660c0ac37903ec4080ca4d3c861ba9342ceb","analyzedAt":"2026-09-03T11:13:55.444Z","contentChangedAt":"2026-09-03T11:13:55.444Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}