0% found this document useful (0 votes)
22 views13 pages

2 Error Handling Documentation

The document provides an overview of the LoliScript class and its functionalities for executing scripts in the LoliScript language, detailing its properties and methods for managing script execution, state, and error handling. It also discusses the RLHttpClientRequestHandler class, which manages HTTP requests and handles potential exceptions like System.UriFormatException. Additionally, the BlockRequest class is introduced, which performs HTTP requests in an automated environment, emphasizing the importance of error handling and URL validation.

Uploaded by

joeblow232123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views13 pages

2 Error Handling Documentation

The document provides an overview of the LoliScript class and its functionalities for executing scripts in the LoliScript language, detailing its properties and methods for managing script execution, state, and error handling. It also discusses the RLHttpClientRequestHandler class, which manages HTTP requests and handles potential exceptions like System.UriFormatException. Additionally, the BlockRequest class is introduced, which performs HTTP requests in an automated environment, emphasizing the importance of error handling and URL validation.

Uploaded by

joeblow232123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

8/13/24, 6:25 PM Word Editor

The LoliScript class within the RuriLib.Legacy.LS namespace is designed to represent a script written in the LoliScript language,
allowing it to be executed line by line. Below is a detailed breakdown of the class and its components:

This class provides a framework for running LoliScript scripts, managing script execution state, handling specific script directives, and
managing the flow of script execution.

Properties

1. Script

Description: Holds the script content as a single string with line breaks separating each line of the script.
Usage: This property is the primary container for the script that will be executed.

2. i

Description: An internal counter used to track the current line number being processed.
Usage: As the script is executed, this counter increments to move through the script line by line.

3. lines

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 1/13
8/13/24, 6:25 PM Word Editor
Description: An array that holds each line of the script as a separate string element.
Usage: The script is split into lines and stored here for easier processing and execution.

4. otherScript

Description: Holds additional script content that may be required during execution, particularly when processing BEGIN
SCRIPT directives.
Usage: This is used to temporarily store script sections that are conditionally executed.

5. language

Description: Specifies the scripting language being used, defaulting to JavaScript.


Usage: Determines how certain script sections are processed, particularly when handling embedded scripts.

6. CurrentLine

Description: Stores the content of the current line being processed.


Usage: This is updated as the script progresses to reflect the line currently under execution.

7. CurrentBlock

Description: Stores the content of the current block being executed, which may consist of multiple lines.
Usage: Helps manage the execution of grouped lines or blocks within the script.

Methods

1. Constructor: LoliScript()

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 2/13
8/13/24, 6:25 PM Word Editor

Purpose: Initializes a new LoliScript object with an empty script.


Usage: Used when you want to create a LoliScript object and later assign a script to it.

2. Constructor: LoliScript(string script)

Purpose: Initializes a new LoliScript object with a specified script.


Parameters:
script : The script to be executed.
Usage: This constructor allows you to immediately assign a script to the object at creation.

Key Functionalities

1. Script Execution Management

The class is designed to manage the step-by-step execution of a script. It includes functionality to:

Track the current line and block of the script being processed.
Handle script directives, such as BEGIN SCRIPT , which may include other languages like JavaScript.

2. State Management

The class includes mechanisms to reset the execution state, determine if the script can continue executing, and handle multi-line script
blocks.

3. Extensibility

The LoliScript class is extensible and can be integrated with other components that require or generate LoliScript, allowing for a
modular approach to scripting in applications like OpenBullet.

Summary

The LoliScript class is a comprehensive tool for handling LoliScript execution, providing all the necessary components to manage,
process, and execute scripts effectively. This class can be extended or modified to accommodate specific use cases where scripting
needs to be executed programmatically in a controlled manner.

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 3/13
8/13/24, 6:25 PM Word Editor

Documentation for ERRORS and EXCEPTIONS


Below is a detailed analysis and documentation of the content relevant to the System.UriFormatException and the overall handling of
HTTP requests in the context of this class.

Overview

The RLHttpClientRequestHandler class is responsible for managing HTTP requests using an HttpClient in a bot-driven environment,
such as the one used by OpenBullet. The primary function of interest is HttpRequestStandard , which performs a standard HTTP
request and handles the response.

Key Components

1. Class Definition

Visibility: The class is internal , meaning it is only accessible within the same assembly.
Inheritance: It inherits from HttpRequestHandler , suggesting it is a specialized version of a more generic handler.

2. Method: HttpRequestStandard

Purpose: This method is responsible for setting up and executing an HTTP request based on the provided
StandardHttpRequestOptions .
Parameters:
data : An instance of BotData , which holds the current state and variables for the bot making the request.
options : An instance of StandardHttpRequestOptions , containing various settings for the HTTP request (e.g., URL,
method, headers).

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 4/13
8/13/24, 6:25 PM Word Editor
Functionality:
Client Initialization: An RLHttpClient is initialized, potentially using a proxy.
Request Setup: A new HttpRequest object is created, with the method, URI, version, headers, and cookies being set
according to the options provided.

3. Error Handling: System.UriFormatException

The method includes the following line:

This line is where a System.UriFormatException could be triggered if the options.Url is not a valid URI.

Potential Issue: If the URL provided in options.Url is improperly formatted, an exception is thrown, specifically
System.UriFormatException .
Handling:
Exception Trigger: The exception occurs when trying to create a new Uri object with an invalid URL format.
System Response: The exception will propagate unless caught, typically causing the bot or task to fail and log the error.

4. Logging and Response Handling

After making the request, the method handles the response, including headers, cookies, and the raw payload.

Headers and Cookies: The response headers and cookies are logged.
Payload Decoding: If the response is gzipped, it attempts to unzip it. The payload is then decoded using UTF-8 or a specified
encoding and is logged.

Summary

The RLHttpClientRequestHandler class in RuriLib.Functions.Http is responsible for executing HTTP requests using configurations
provided by a bot. The HttpRequestStandard method sets up the request, manages cookies and headers, and processes the response.
A System.UriFormatException may occur if the URL provided is not in a valid format, which is a critical point where error handling
should be implemented to ensure robustness in bot operations.

BlockRequest.cs

The file BlockRequest.cs defines a class called BlockRequest within the RuriLib.Legacy.Blocks namespace. This class is
responsible for performing HTTP requests as part of a broader automation or scripting task. Below is a detailed breakdown of the
content.

Class Overview

namespace RuriLib.Legacy.Blocks
{
/// <summary>
/// A block that can perform HTTP requests.
/// </summary>
public class BlockRequest : BlockBase
{
// Class implementation...
}
}

Namespace: RuriLib.Legacy.Blocks
Purpose: This class is designed to execute HTTP requests, making it a crucial component for tasks such as web scraping, API
interaction, or automated testing.

Properties

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 5/13
8/13/24, 6:25 PM Word Editor
1. Url

/// <summary>The URL to call, including additional GET query parameters.</summary>


public string Url { get; set; } = "https://google.com";

Description: This property holds the URL to which the HTTP request will be sent.
Default Value: It defaults to "https://google.com" .

2. RequestType

/// <summary>The request type.</summary>


public RequestType RequestType { get; set; } = RequestType.Standard;

Description: Specifies the type of HTTP request (e.g., standard, multipart).


Default Value: RequestType.Standard .

3. AuthUser and AuthPass

// Basic Auth /// <summary>The username for basic auth requests.</summary>


public string AuthUser { get; set; } = "";

/// <summary>The password for basic auth requests.</summary> public string AuthPass { get; set; } = "";

Description: These properties are used for basic HTTP authentication, storing the username and password.

4. PostData

/// <summary>The content of the request, sent after the headers. Use '\n' to input a linebreak.</summary>
public string PostData { get; set; } = "";

Description: Contains the data that will be sent in the body of the HTTP request, typically used in POST requests.

5. RawData

/// <summary>The content of the request as a raw HEX string that will be sent as a bytestream.</summary>
public string RawData { get; set; } = "";

Description: If the request needs to send raw byte data, it can be specified here as a HEX string.

6. Method

/// <summary>The method of the HTTP request.</summary>


public HttpMethod Method { get; set; } = HttpMethod.GET;

Description: Determines the HTTP method used for the request (e.g., GET, POST).

7. SecurityProtocol

/// <summary>The security protocol(s) to use for the HTTPS request.</summary> public SecurityProtocol SecurityProtocol { get; set; } =
SecurityProtocol.SystemDefault;

Description: Specifies the security protocol (e.g., SSL, TLS) to use for secure HTTP requests.

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 6/13
8/13/24, 6:25 PM Word Editor
8. CustomHeaders

/// <summary>The custom headers that are sent in the HTTP request.</summary>
public Dictionary<string, string> CustomHeaders { get; set; } = new Dictionary<string, string>();

Description: A dictionary to hold any custom headers that should be included in the HTTP request.

Line 34: Method ' Process'

The line you referenced corresponds to the method call Process(LSGlobals ls) within this file. Below is an overview and documentation
for this specific line:

public void Process(LSGlobals ls)


{
// Method implementation...
}

Method Name: Process


Parameters:
ls : An instance of LSGlobals , which likely holds global variables and state relevant to the LoliScript being executed.
Purpose: The Process method is where the HTTP request is actually executed. It uses the properties defined above to configure
the request and then sends it. The results are processed and stored in the ls object for further use in the script.

Exception Handling in Process

Given that the Process method deals with HTTP requests, it’s crucial to handle exceptions, such as network errors, invalid URLs, or
unexpected responses. This method would typically include try-catch blocks to catch exceptions like UriFormatException or
HttpRequestException and log them appropriately.

Summary

The BlockRequest class in the RuriLib.Legacy.Blocks namespace is a foundational component for making HTTP requests in a
scripted or automated environment. The Process method is central to executing these requests, leveraging the properties defined
within the class to customize each request. Proper exception handling within this method ensures that errors are caught and managed,
preventing the script from failing unexpectedly.

1. LoliScript.cs - TakeStep Method

The TakeStep method is crucial for the execution of LoliScript blocks. Here’s a deeper look at how it operates:

Key Responsibilities:

Line Processing: The method processes each line in the script, skipping over comments or empty lines, and
concatenating indented lines for more complex command structures.
Block Identification: It identifies if the current line corresponds to a block (like a REQUEST block). If it does, the
block is parsed and processed.
Error Handling: Any errors during block processing, particularly a BlockProcessingException , are caught, logged,
and potentially re-thrown if they are critical.

How Errors are Managed:

Block Execution: When a block like REQUEST is identified, it is parsed and processed. If something goes wrong
during this process, such as an invalid URL, an exception is thrown.
Logging and Recovery: The code logs the error with a level of detail depending on the VerboseMode setting. If
the exception is critical (like a BlockProcessingException due to an invalid URI), it can halt the execution.

2. BlockRequest.cs - Processing the HTTP Request

The BlockRequest class is responsible for executing HTTP requests, which is where the invalid URI error likely occurs.

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 7/13
8/13/24, 6:25 PM Word Editor
Key Responsibilities:

Setting Up the Request: The class constructs the HTTP request, including setting up the URL, headers,
authentication details, and other options.
URL Handling: The Url property is processed using ReplaceValues(Url, ls) to substitute any variables with
actual values before making the request.
Error Handling: If the URL is malformed, this is where the UriFormatException would be thrown, leading to the
error you're seeing.

Detailed Error Path:

1. URL Substitution: The ReplaceValues(Url, ls) function is intended to substitute placeholders in the URL with
actual values. If the final URL is invalid (e.g., missing a scheme like http:// ), this will cause a UriFormatException .
2. Request Execution: Once the URL and other parameters are set, the request is executed. If the URL is invalid, the
exception is caught by the TakeStep method in LoliScript.cs .

Handling the UriFormatException :

To make the system more robust, consider the following improvements:

1. Pre-Validation of the URL: Before attempting to execute the HTTP request, validate the URL format. This could be
done in BlockRequest.cs right after the URL is generated but before the request is made:

Uri uriResult;
bool validUrl = Uri.TryCreate(Url, UriKind.Absolute, out uriResult) && (uriResult.Scheme ==
Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!validUrl)
{
throw new BlockProcessingException($"Invalid URI: {Url}. The format of the URI could not be determined.");
}

2. Detailed Logging: Ensure that detailed logging is in place to capture the full context of the error, including the URL
and the state of other parameters. This can help in debugging issues faster.

3. Graceful Degradation: Depending on the criticality of the request, you might want to add fallback logic or
alternative actions if the URL is invalid. This could involve retrying with a corrected URL or notifying the user to
correct the input.

Conclusion:

The error you encountered is a common one when dealing with dynamic URLs in scripting environments. By enhancing
the validation and error handling in both the TakeStep method of LoliScript.cs and the BlockRequest.cs class, you
can prevent such issues from causing unexpected failures in your scripts.

ERROR: System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
at RuriLib.Functions.Http.RLHttpClientRequestHandler.HttpRequestStandard(BotData data,
StandardHttpRequestOptions options) in /code/RuriLib/Functions/Http/RLHttpClientRequestHandler.cs:line 34
at RuriLib.Legacy.Blocks.BlockRequest.Process(LSGlobals ls) in /code/RuriLib/Legacy/Blocks/BlockRequest.cs:line 394
at RuriLib.Legacy.LS.LoliScript.TakeStep(LSGlobals ls) in /code/RuriLib/Legacy/LS/LoliScript.cs:line 213
[Executing block: REQUEST] BlockProcessingException: RuriLib.Legacy.Exceptions.BlockProcessingException: Invalid URI:
The format of the URI could not be determined.
at RuriLib.Legacy.LS.LoliScript.TakeStep(LSGlobals ls) in /code/RuriLib/Legacy/LS/LoliScript.cs:line 227
at RuriLib.Models.Debugger.ConfigDebugger.Run() in /code/RuriLib/Models/Debugger/ConfigDebugger.cs:line 286

The error you provided outlines a sequence of method calls leading up to a System.UriFormatException caused by an
invalid URI. Below is an analysis of the error, the code involved, and how you can address it.

Error Breakdown

1. System.UriFormatException :

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 8/13
8/13/24, 6:25 PM Word Editor
Cause: This exception is thrown when the Uri constructor receives a string that does not conform to a
valid URI format.
Stack Trace:
System.Uri.CreateThis : This method is where the URI validation fails. It’s the internal method
used to create and validate the URI.
RLHttpClientRequestHandler.HttpRequestStandard (Line 34): This is the method where the
invalid URI is being passed to create a Uri object.
BlockRequest.Process (Line 394): This method calls HttpRequestStandard , likely passing the
invalid URI.
LoliScript.TakeStep (Lines 213 and 227): The LoliScript engine is executing the block, and when it
encounters the REQUEST block, it triggers the Process method, which in turn calls
HttpRequestStandard .
ConfigDebugger.Run (Line 286): This is likely the overarching method that is running the script
in a debugging or execution context.

Involved Code Analysis

1. RLHttpClientRequestHandler.HttpRequestStandard :

This method is responsible for making the HTTP request. The line in question (line 34) is where the URI is
constructed from the provided URL.
The error suggests that the URL passed to this method is not a valid URI, which causes the
UriFormatException .

2. BlockRequest.Process :

This method handles the HTTP request logic for the REQUEST block.
It likely receives the URL from the script, processes it (e.g., substituting variables), and passes it to
HttpRequestStandard .
If the URL is malformed, this is where the error propagates from.

3. LoliScript.TakeStep :

This method processes each step (or block) in the LoliScript.


When it encounters the REQUEST block, it calls the Process method of BlockRequest .
The error indicates that the block is failing due to the invalid URI.

Potential Causes

Malformed URL: The URL provided in the script might be missing a scheme (like http:// ), contain illegal characters,
or be incomplete.
Variable Substitution Error: If the URL is dynamically generated using variables, those variables might be empty or
incorrectly formatted.

Suggested Fixes

1. Pre-Validation of URLs:

Before passing the URL to HttpRequestStandard , ensure it is validated. This can be done by adding a
check in BlockRequest.Process or directly in HttpRequestStandard :

Uri uriResult;
bool validUrl = Uri.TryCreate(Url, UriKind.Absolute, out uriResult) && (uriResult.Scheme ==
Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!validUrl)
{
throw new BlockProcessingException($"Invalid URI: {Url}. The format of the URI could not be determined.");
}

2. Error Handling in LoliScript.TakeStep :

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 9/13
8/13/24, 6:25 PM Word Editor
Enhance the error handling in TakeStep to provide more context or potentially recover from non-critical
errors.

3. Script Debugging:

Review the script that is being executed to ensure that the URL being passed to the REQUEST block is
correctly formatted.
Use logging to output the exact URL being used before the request is made, which can help identify if and
where the URL is being malformed.

Conclusion

The System.UriFormatException indicates that the script is passing an invalid URL to the HTTP request handler. By
implementing URL validation and enhancing error handling, you can prevent this exception from disrupting the execution
of the script. Additionally, debugging the script itself to ensure that URLs are correctly formatted will help avoid these
issues in the future.

The System.UriFormatException typically indicates that the URL being used is malformed or does not conform to a valid
URL structure. This could mean:

1. Malformed URL: The URL is not formatted correctly. For example, it might be missing a scheme ( http:// or
https:// ), contain illegal characters, or be incomplete. This is often the cause when dealing with dynamically
generated URLs in scripts.

2. Invalid or Non-Existent Endpoint: The URL might be well-formed but points to an endpoint that no longer exists or
is unreachable. This would typically result in a different error (like a 404 Not Found), but if the URL itself is
malformed before reaching the endpoint, it would throw a UriFormatException .

Addressing the Issue

If the error is due to a malformed URL, then validating and correcting the URL within the script should resolve the issue.
This was the approach suggested with the validation logic I provided.

However, if the error arises because the URL or endpoint is no longer valid or accessible, this would require a different
approach:

1. Check the Endpoint: Ensure that the URL points to a valid and reachable endpoint. You can manually verify this by
pasting the URL into a web browser or using a tool like curl to see if it returns a valid response.

2. Update the URL: If the endpoint has changed or is no longer available, you will need to update the URL in your
LoliScript to point to the correct endpoint.

3. Handle Legacy URLs: If the URL structure has changed (e.g., due to a website update), you might need to adjust
the script to match the new format or find alternative endpoints.

Steps to Fix and Validate the URL

1. Manual Check:

Paste the URL in a web browser to see if it loads.


Use a tool like curl or Postman to check if the endpoint responds.

2. Dynamic URL Validation in LoliScript:

Implement the validation function as suggested earlier to catch malformed URLs dynamically.

3. Update LoliScript:

If you identify that the endpoint has changed, update the URLs in the script accordingly.

Conclusion

If the URL is malformed, the validation and correction within the script should fix the issue.
If the endpoint is no longer valid or reachable, you will need to find the correct URL and update the script.

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 10/13
8/13/24, 6:25 PM Word Editor
By ensuring that the URLs used in your script are valid and reachable, you can avoid the System.UriFormatException .

The System.UriFormatException typically indicates that the URL being used is malformed or does not conform to a valid
URL structure. This could mean:

1. Malformed URL: The URL is not formatted correctly. For example, it might be missing a scheme ( http:// or
https:// ), contain illegal characters, or be incomplete. This is often the cause when dealing with dynamically
generated URLs in scripts.

2. Invalid or Non-Existent Endpoint: The URL might be well-formed but points to an endpoint that no longer exists or
is unreachable. This would typically result in a different error (like a 404 Not Found), but if the URL itself is
malformed before reaching the endpoint, it would throw a UriFormatException .

To prevent the System.UriFormatException in your LoliScript, we can add validation steps before each
REQUEST block. This validation will ensure that the URLs are properly formatted before attempting to make the
requests.

Here's how you can modify the LoliScript:

Step 1: Create a Validation Function

You can create a simple validation function that checks if the URL is valid. If the URL is not valid, it can either skip
the request or jump to an error-handling section.

loliscript

Step 2: Integrate Validation Before Each Request

For each REQUEST block in your LoliScript, validate the URL first:

loliscript

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 11/13
8/13/24, 6:25 PM Word Editor
Repeat this validation for all other REQUEST blocks:

loliscript

Step 3: Handle Errors

Optionally, create an error-handling section:

loliscript

Summary of Changes

Validation Function: The CheckValidUrl function validates if the URL starts with "http://" or "https://". If
not, it sets IsValid to FALSE .
Pre-Validation: Before each REQUEST block, the script checks if the URL is valid. If it’s valid, the request
proceeds; otherwise, the script logs the invalid URL and jumps to an error-handling section.
Error Handling: If an invalid URL is detected, the script logs an error and stops execution.

This approach should prevent the System.UriFormatException by ensuring that only valid URLs are passed to
the REQUEST blocks. You can customize the validation logic further if needed.

Addressing the Issue

If the error is due to a malformed URL, then validating and correcting the URL within the script should resolve the issue.
This was the approach suggested with the validation logic I provided.

However, if the error arises because the URL or endpoint is no longer valid or accessible, this would require a different
approach:

1. Check the Endpoint: Ensure that the URL points to a valid and reachable endpoint. You can manually verify this by
pasting the URL into a web browser or using a tool like curl to see if it returns a valid response.

2. Update the URL: If the endpoint has changed or is no longer available, you will need to update the URL in your
LoliScript to point to the correct endpoint.

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 12/13
8/13/24, 6:25 PM Word Editor
3. Handle Legacy URLs: If the URL structure has changed (e.g., due to a website update), you might need to adjust
the script to match the new format or find alternative endpoints.

Steps to Fix and Validate the URL

1. Manual Check:

Paste the URL in a web browser to see if it loads.


Use a tool like curl or Postman to check if the endpoint responds.

2. Dynamic URL Validation in LoliScript:

Implement the validation function as suggested earlier to catch malformed URLs dynamically.

3. Update LoliScript:

If you identify that the endpoint has changed, update the URLs in the script accordingly.

Conclusion

If the URL is malformed, the validation and correction within the script should fix the issue.
If the endpoint is no longer valid or reachable, you will need to find the correct URL and update the script.

By ensuring that the URLs used in your script are valid and reachable, you can avoid the System.UriFormatException . If
you encounter URLs that consistently cause this issue, they likely need to be updated or corrected.

chrome-extension://fehbhooigaekgcjecehkiflmflofpdke/data/interface/index.html?win 13/13

You might also like