LLmAgentsBasicTools/Src/Utils/ErrDescription.mqh
Nique_372 e38de02cdf
2026-07-15 12:34:01 -05:00

59 lines
2.6 KiB
MQL5

//+------------------------------------------------------------------+
//| ErrDescription.mqh |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com/"
#property strict
#ifndef LLMAGENTSBASICTOOLS_SRC_UTILS_ERR_DESCRIPTION_MQH
#define LLMAGENTSBASICTOOLS_SRC_UTILS_ERR_DESCRIPTION_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "..\\Def.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| name: get_err_description |
//| desc: Returns the human readable description of an MT5 error |
//| code |
//| params: |
//| error_code integer MT5 error code. Default -1 |
//| include_code boolean If true prefixes the description with |
//| the numeric code. Default true |
//+------------------------------------------------------------------+
class CLlmBToolGetErrDescription : public CLLmTool
{
public:
CLlmBToolGetErrDescription(void) : CLLmTool("get_err_description") {}
~CLlmBToolGetErrDescription(void) {}
void Run(CJsonNode& param, CJsonBuilderStr* &out) override final
{
out = m_shared_builder;
const int error_code = int(param["error_code"].ToInt(-1));
const bool include_code = param["include_code"].ToBool(true);
//---
string err = "";
CMt5ErrorDesc::GetError(err, error_code, include_code);
//---
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS(err);
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
}
};
}
//+------------------------------------------------------------------+
#endif // LLMAGENTSBASICTOOLS_SRC_UTILS_ERR_DESCRIPTION_MQH