{"record":{"id":"67ade7c505bbb172","repo":"inancgumus/learngo","slug":"socket-is-out-of-power-for-dkw","errorCode":null,"errorMessage":"socket is out of power for %dkW","messagePattern":"socket is out of power for (.+?)kW","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"interfaces/04-interfaces/power/socket.go","lineNumber":32,"sourceCode":"// Plug a device to draw power from the `Socket`\nfunc (s *Socket) Plug(device PowerDrawer) error {\n\tn := rand.Intn(50) + 1\n\n\tif s.power-n < 0 {\n\t\treturn fmt.Errorf(\"socket is out of power for %dkW\", n)\n\t}\n\n\ts.power -= n\n\tdevice.Draw(n)\n\n\treturn nil\n}","sourceCodeStart":14,"sourceCodeEnd":40,"githubUrl":"https://github.com/inancgumus/learngo/blob/3c475a78e54336c6255e925ff66b8ef4da6a2ae7/interfaces/04-interfaces/power/socket.go#L14-L40","documentation":"Socket.Plug simulates a device drawing a random 1-50 kW amount; if s.power-n would go below zero, the socket cannot satisfy the request, so it returns this formatted error instead of draining power or calling device.Draw. The %d is the randomly requested amount, not the socket's remaining power.","triggerScenarios":"Thrown at interfaces/04-interfaces/power/socket.go:32 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the returned error after Plug and print/report it; the device is not powered.","Retry Plug later, since the random draw may succeed once power behavior changes or the socket is recharged.","Reduce device power requirements so a 1-50 kW draw fits within the remaining socket power."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3c475a78e54336c6255e925ff66b8ef4da6a2ae7","analyzedAt":"2026-09-02T10:14:38.492Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}