error 001: expected token: "=", but found "[" - pawn

got this error on this line:
const int restricted_weapons[] = { WEAPON_AK47, WEAPON_AWP, WEAPON_M4A4 };"
By the way this is SourcePawn
i thought about something but it did not work

Related

nlohmann's json library syntax error while parsing

I have tried many different ways of doing this but it keeps giving me the same exact error.
std::string username = "Lethal";
std::string password = "test123";
std::ifstream f("DBs/test.json");
json data = json::parse(f);
data["username"] = username;
data["password"] = password;
terminate called after throwing an instance of 'nlohmann::detail::parse_error'
what(): [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpect
ed end of input; expected '[', '{', or a literal
JSON File:
{
"username": "",
"password": " "
}

AWS C++ Route53 Unknown(100) errors

I'm trying to query a hosted zone on AWS with the C++ SDK and its not giving me error messages I can use (UNKNOWN/100/No message). I have dumped the request as well and don't see anything obviously wrong with it.
Any help on where I might look for a problem?
// note: The zone_id has been pulled correctly earlier in the code
Aws::String zone_id = "(set previously)";
auto type = Model::RRType::A;
// List records
{
auto lrrs = Model::ListResourceRecordSetsRequest();
lrrs.SetHostedZoneId(zone_id);
lrrs.SetStartRecordType(type);
auto outcome = route53->ListResourceRecordSets(lrrs);
if (outcome.IsSuccess())
{
std::cout << "LRRS worked\n";
auto result = outcome.GetResult().GetResourceRecordSets();
for (auto &r : result)
{
std::cout << r.GetName() << ":"
<< r.GetTTL() << ":"
<< static_cast<char>(r.GetType()) << std::endl;
}
}
else
{
std::cerr << "LRRS failed: "
<< static_cast<int>(outcome.GetError().GetErrorType())
<< std::endl
<< outcome.GetError()
<< std::endl;
}
}
This is the error I end up with when I run it:
LRRS failed: 100
HTTP response code: 400
Resolved remote host IP address: 55.146.15.201
Request ID:
Exception name:
Error message: No response body.
3 response headers:
connection : close
content-length : 0
date : Sun, 30 May 2021 01:50:29 GMT
I have tried all sorts of combinations on how to construct the query but with no luck. Any help would be much appreciated!
Ok I figured it out.
The zone_id returned via AWS API (ListHostedZonesByName) has reply like this:
/hostedZoneId/HSFDGFHJFFSDSRTDDD
The problem is, all the API afterwards don't expect to see the prefix and only expect to see HSFDGFHJFFSDSRTDDD. The same problem happened a few other places (ChangeResourceRecordSets, GetChange) and there's nothing obvious in the documents to explain this!
Hope this helps anyone else stumbling on this.

SyntaxError: Invalid regular expression: /INFO/: Unterminated character class at new RegExp (<anonymous>)

Code:
it.only('should display logs in color when using chalk', () => {
// Setup.
const uuid = uuidv4();
const messages = [
// prettier-ignore
[`${uuid}_chalk_info`, '\[37mINFO\[39m'],
[`${uuid}_chalk_debug`, '\[36mDEBUG\[39m'],
[`${uuid}_chalk_trace`, '\[32mTRACE\[39m']
];
testLog(messages[0][1]);
const log = languramaLog({ ...defaultTerminalConfiguration, level: 'trace', chalk });
const mock = jest.spyOn(process.stdout, 'write').mockImplementation(() => {});
// Test.
log.info(messages[0][0]);
log.debug(messages[1][0]);
log.trace(messages[2][0]);
// Assert.
expect(mock).toHaveBeenCalledTimes(3);
expect(mock).toHaveBeenCalledWith(jasmine.stringMatching(messages[0][1]));
expect(mock).toHaveBeenCalledWith(jasmine.stringMatching(messages[1][1]));
expect(mock).toHaveBeenCalledWith(jasmine.stringMatching(messages[2][1]));
});
Error:
SyntaxError: Invalid regular expression: /INFO/: Unterminated character class
at new RegExp (<anonymous>)
359 | // Assert.
360 | expect(mock).toHaveBeenCalledTimes(3);
> 361 | expect(mock).toHaveBeenCalledWith(jasmine.stringMatching(messages[0][1]));
| ^
362 | expect(mock).toHaveBeenCalledWith(jasmine.stringMatching(messages[1][1]));
363 | expect(mock).toHaveBeenCalledWith(jasmine.stringMatching(messages[2][1]));
364 | });
So I'm using the package chalk to create colors for some logs which I would like to test to make sure that the logs are being printed to the terminal. However the RegEx in jasmine seems to complain, any ideas?
The following works fine:
const log = new RegExp(/\[37mINFO\[39m/);
const result = log.test('[90m2020-05-02 23:54:51 UTC+2[39m [37mINFO[39m 2df268af-af1f-42f0-b098-d52fb0123d95_chalk_info [90m/home/karl/dev/langurama/log/test/index.node.spec.js:358:17[39m');
console.log(result); // true
In Regexen built from string literals you have to double the escape character: one instance is to escape \ in the string literal to arrive at the regex escape character for the Regexp.
So your pattern would look like:
\\[37mINFO\\[39m
Test cases:
let re_s
, re_d
, re_s_nostring
, re_d_nostring
;
try { re_s = new RegExp ( '\[37mINFO\[39m', 'g' ); } catch (e) { console.log('re_s: constructor fails.\n' ); } // This always fails.
try { re_d = new RegExp ( '\\[37mINFO\\[39m', 'g' ); } catch (e) { console.log('re_d: constructor fails.\n' ); }
try { re_s_nostring = /\[37mINFO\[39m/g; } catch (e) { console.log('re_s_nostring: constructor fails.\n' ); }
// Syntactically wrong, won't compile into bytecode
// re_d_nostring = /\\[37mINFO\\[39m/g;
if (re_d) { console.log ( re_d.test("[37mINFO[39m") ? "re_d matches" : "re_d does not match" ); }
if (re_s_nostring) { console.log ( re_s_nostring.test("[37mINFO[39m") ? "re_s_nostring matches" : "re_s_nostring does not match" ); }

socket.io why assert(false)

I am developing a program in C++ to communicate over Socket.IO and I am referring the console example. At line 77-78 we have the following statements :
string user = data->get_map()["username"]->get_string();
string message = data->get_map()["message"]->get_string();
If I go to sio_message.h on line 101 we have definition of map method as given bellow. On line 103 their is an assert(false) statement which is causing my program to fail. Can anyone enlighten me why this assert(false) statement is present.
virtual std::map<std::string,message::ptr>& get_map()
{
assert(false); ///why this???
static std::map<std::string,message::ptr> s_empty_map;
s_empty_map.clear();
return s_empty_map;
}
My Code :
void Socket_IO::receive_listener(std::string const&name, sio::message::ptr const& data, bool hasAck, sio::message::list &ack_resp)
{
spdlog::info("Data Recieved : " + data->get_map()["message"]->get_string()); // I am getting an Socket.IO exception here
spdlog::info("Message Name : " + name);
}

Sending POST using cpprest

I have the following code to send POST, but I am getting an error with that even it compile correctly
http_client client(U("http://l0.71.103.63:34568"));
json::value postData;
postData["name"] = json::value::string(U("Mohammad"));
http_response response = client.request(methods::POST,postData.to_string().c_str()).get();
if(response.status_code() == status_codes::OK)
{
auto body = response.extract_string();
std::wcout << L"Added new Id: " << body.get().c_str() << std::endl;
return std::stoi(body.get().c_str());
}
But I am getting the following error when try to run the program
terminate called after throwing an instance of 'web::uri_exception'
what(): provided uri is invalid: {"name":"Mohammad"}
Aborted (core dumped)
I think the problem is your IP address. It looks like your IP address is wrong? You have "http://l0." where the "10" is "l0" (lowercase L).
Hence the web:uri_exception.
You are wrong (I do think) in your request, should look like that:
auto response = client.request(methods::POST, U("\"), postData).get();
The second argument in the request is the URL complement, and you are passing your json in string, hence the error you have.
basically the syntax you want is this one:
pplx::task web::http::client::http_client::request (
const method & mtd, const utility::string_t &
path_query_fragment, const json::value & body_data, const
pplx::cancellation_token & token = pplx::cancellation_token::none()
)