knit_script.knit_script_exceptions.ks_exceptions module
Module of common Knit Script Exceptions.
This module contains the exception classes used throughout the KnitScript programming language. These exceptions cover various failure modes including assertion failures, parsing errors, machine operation conflicts, configuration errors, and fabric state issues. Each exception provides detailed context about the specific error condition and includes relevant information for debugging and error recovery.
- exception Knit_Script_Assertion_Exception(assertion_statement, condition, condition_value, assertion_report=None)[source]
Bases:
AssertionError
,Knit_Script_Located_Exception
Exception raised when a KnitScript assertion fails.
This exception is thrown when an assertion statement in KnitScript code evaluates to a falsy value. It provides detailed information about the failed condition and its actual value, along with any additional assertion report information that was provided with the assertion.
- Parameters:
assertion_statement (
KS_Element
)condition (
Any
)condition_value (
Any
)
- __init__(assertion_statement, condition, condition_value, assertion_report=None)[source]
Initialize the Knit_Script_Assertion_Exception.
- Parameters:
assertion_statement (Assertion_Statement) – The assertion statement from the knitscript file used to locate this error.
condition (Any) – The assertion condition that failed, typically an expression or condition object.
condition_value (Any) – The actual value that caused the assertion to fail.
assertion_report (str | None, optional) – Optional additional report information about the assertion failure. Defaults to None.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- error_location: Location
- exception Needle_Instruction_Type_Exception(needle_expression, instruction_type)[source]
Bases:
Knit_Script_Located_Exception
Exception raised when providing an invalid instruction type to a carriage pass of needle instructions.
- This exception occurs when an instruction type that is not valid for needle operations is used in a context that expects needle-specific instructions
such as knit, tuck, miss, split, xfer, or drop operations.
- Parameters:
needle_expression (
KS_Element
)instruction_type (
Knitout_Instruction_Type
)
- __init__(needle_expression, instruction_type)[source]
Initialize the Needle_Instruction_Type_Exception.
- Parameters:
needle_expression (Needle_Instruction_Exp) – The Needle Instruction Expression used to locate the source of this error.
instruction_type (Knitout_Instruction_Type) – The invalid instruction type that was provided.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- error_location: Location
- exception Incompatible_In_Carriage_Pass_Exception(source_statement, first_instruction, second_instruction)[source]
Bases:
Knit_Script_Located_Exception
Exception raised when instructions are combined in a carriage pass that are incompatible.
This exception occurs when two or more instruction types are used together in a single carriage pass but cannot be executed simultaneously due to machine limitations or logical conflicts.
- first_instruction
The first instruction in the incompatible combination.
- Type:
Knitout_Instruction_Type
- second_instruction
The second instruction in the incompatible combination.
- Type:
Knitout_Instruction_Type
- Parameters:
source_statement (
KS_Element
)first_instruction (
Knitout_Instruction_Type
)second_instruction (
Knitout_Instruction_Type
)
- __init__(source_statement, first_instruction, second_instruction)[source]
Initialize the Incompatible_In_Carriage_Pass_Exception.
- Parameters:
source_statement (KS_Element) – The source statement of the carriage pass.
first_instruction (Knitout_Instruction_Type) – The first instruction type in the incompatible combination.
second_instruction (Knitout_Instruction_Type) – The second instruction type in the incompatible combination.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- error_location: Location
- exception Required_Direction_Exception(source_statement, instruction_type)[source]
Bases:
Knit_Script_Located_Exception
Exception raised when attempting a carriage pass without specifying a direction for yarn-carrier operations.
This exception occurs when operations that require yarn carriers are attempted without establishing a carriage direction, which is necessary for proper yarn handling and loop formation.
- instruction_type
The instruction type that requires a direction.
- Type:
Knitout_Instruction_Type
- Parameters:
source_statement (
KS_Element
)instruction_type (
Knitout_Instruction_Type
)
- __init__(source_statement, instruction_type)[source]
Initialize the Required_Direction_Exception.
- Parameters:
source_statement (KS_Element) – The source statement of the carriage pass.
instruction_type (Knitout_Instruction_Type) – The instruction type that requires a direction.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- error_location: Location
- exception Repeated_Needle_Exception(source_statement, needle)[source]
Bases:
Knit_Script_Located_Exception
Exception raised when a carriage pass would require passing over the same needle more than once.
This exception prevents machine operations that would attempt to work on the same needle multiple times within a single carriage pass, which is not physically possible on most knitting machines.
- needle
The needle that would be worked on multiple times.
- Type:
Needle
- Parameters:
source_statement (
KS_Element
)needle (
Needle
)
- __init__(source_statement, needle)[source]
Initialize the Repeated_Needle_Exception.
- Parameters:
source_statement (KS_Element) – The source statement of the carriage pass.
needle (Needle) – The needle that would be worked on multiple times.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- error_location: Location
- exception All_Needle_Operation_Exception(source_statement, first_needle, second_needle, racking, instruction)[source]
Bases:
Knit_Script_Located_Exception
Exception raised when an all-needle operation occurs without an all-needle racking.
This exception occurs when operations that require all needles to be properly aligned (such as certain transfer operations) are attempted when the machine racking is not set to an all-needle position.
- first_needle
The first needle in the operation.
- Type:
Needle
- second_needle
The second needle in the operation.
- Type:
Needle
- instruction
The instruction type being attempted.
- Type:
Knitout_Instruction_Type
- Parameters:
source_statement (
KS_Element
)first_needle (
Needle
)second_needle (
Needle
)racking (
int
)instruction (
Knitout_Instruction_Type
)
- __init__(source_statement, first_needle, second_needle, racking, instruction)[source]
Initialize the All_Needle_Operation_Exception.
- Parameters:
source_statement (KS_Element) – The source statement of the carriage pass.
first_needle (Needle) – The first needle in the operation.
second_needle (Needle) – The second needle in the operation.
racking (int) – The current racking value.
instruction (Knitout_Instruction_Type) – The instruction type being attempted.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- error_location: Location
- exception No_Declared_Carrier_Exception(in_direction_statement)[source]
Bases:
Knit_Script_Located_Exception
Exception raised when no working carrier has been declared for operations that require one.
This exception occurs when knitting or tucking operations are attempted without first declaring a working yarn carrier, which is necessary for these operations to form proper loops.
- Parameters:
in_direction_statement (
KS_Element
)
- __init__(in_direction_statement)[source]
Initialize the No_Declared_Carrier_Exception.
- Parameters:
in_direction_statement (In_Direction_Statement) – The input direction statement used to locate the error in the knit-script file.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- error_location: Location