inancgumus/learngo · error

socket is out of power for %dkW

Error message

socket is out of power for %dkW

What it means

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.

Source

Thrown at interfaces/04-interfaces/power/socket.go:32

// Plug a device to draw power from the `Socket`
func (s *Socket) Plug(device PowerDrawer) error {
	n := rand.Intn(50) + 1

	if s.power-n < 0 {
		return fmt.Errorf("socket is out of power for %dkW", n)
	}

	s.power -= n
	device.Draw(n)

	return nil
}

View on GitHub (pinned to 3c475a78e5)

Solutions

  1. Check the returned error after Plug and print/report it; the device is not powered.
  2. Retry Plug later, since the random draw may succeed once power behavior changes or the socket is recharged.
  3. Reduce device power requirements so a 1-50 kW draw fits within the remaining socket power.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at interfaces/04-interfaces/power/socket.go:32 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02). Data as JSON: /api/errors/67ade7c505bbb172. Report an issue: GitHub.