Class: Kobako::Execution

Inherits:
Object
  • Object
show all
Defined in:
lib/kobako/execution.rb,
sig/kobako/execution.rbs

Overview

Kobako::Execution — the frozen result of one Sandbox#eval / #run: the decoded #value plus the run's output captures and #usage. A successful run returns it; a failed run raises an error carrying the same frozen Execution on the error's #execution, so a rescue reads the captures and usage exactly as a successful caller reads them off the return value. On a failed run #value is nil — only the captures and usage are meaningful.

#failed? tells the returned Execution from the carried one even when both #value are nil (a run whose last expression was nil versus a failed one). It holds no reference to the raising error, so the error carries the Execution but not the reverse.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, usage:, stdout:, stderr:, failed:) ⇒ Execution

Returns a new instance of Execution.



25
26
27
28
29
30
31
32
# File 'lib/kobako/execution.rb', line 25

def initialize(value:, usage:, stdout:, stderr:, failed:)
  @value = value
  @usage = usage
  @stdout_capture = stdout
  @stderr_capture = stderr
  @failed = failed
  freeze
end

Instance Attribute Details

#usageKobako::Usage (readonly)

The Kobako::Usage resource accounting for this run.

Returns:



23
24
25
# File 'lib/kobako/execution.rb', line 23

def usage
  @usage
end

#valueObject (readonly)

The deserialized guest value the run produced; nil on a failed run.

Returns:

  • (Object)


20
21
22
# File 'lib/kobako/execution.rb', line 20

def value
  @value
end

Instance Method Details

#failed?Boolean

Returns true iff the run failed — false on the Execution #eval / #run returned, true on the one a raised error carries.

Returns:

  • (Boolean)


36
# File 'lib/kobako/execution.rb', line 36

def failed? = @failed

#stderrString

Bytes the guest wrote to stderr during this run. Mirror of #stdout.

Returns:

  • (String)


44
# File 'lib/kobako/execution.rb', line 44

def stderr = @stderr_capture.bytes

#stderr_truncated?Boolean

Returns true iff stderr capture reached stderr_limit during this run.

Returns:

  • (Boolean)


50
# File 'lib/kobako/execution.rb', line 50

def stderr_truncated? = @stderr_capture.truncated?

#stdoutString

Bytes the guest wrote to stdout during this run as a UTF-8 String, clipped at stdout_limit; the content carries no truncation sentinel, so use #stdout_truncated? to observe overflow.

Returns:

  • (String)


41
# File 'lib/kobako/execution.rb', line 41

def stdout = @stdout_capture.bytes

#stdout_truncated?Boolean

Returns true iff stdout capture reached stdout_limit during this run.

Returns:

  • (Boolean)


47
# File 'lib/kobako/execution.rb', line 47

def stdout_truncated? = @stdout_capture.truncated?