Skip to content

"Type safety" #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2020
Merged

"Type safety" #21

merged 3 commits into from
Mar 11, 2020

Conversation

erickhun
Copy link
Collaborator

We got few incidents when passing the wrong type of parameters. Since it makes the PHP erroring out and make a full service stop, I simply output an error message instead of stopping the script execution.

I was thinking to use the type-hint but since we use the magic function call_user_func_array i'm not too sure how to do it altogether.

@colinscape up for a review?

@erickhun erickhun requested review from esclapes and colinscape March 10, 2020 13:14
Copy link

@colinscape colinscape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wonder if we will end up 'losing' these logs which go to error_log.

What would you think about re-packaging the malformed arguments and flagging them with something like malformed: true so we could detect them?

For example, if the arguments don't satisfy the conditions in checkLogParametersType() we could instead call BuffLog with something like BuffLog::warning('Malformed BuffLog request', ['malformed' = true, 'args' => $args]); We would need to be careful of not creating an infinite loop, admittedly! 😅

@erickhun
Copy link
Collaborator Author

@colinscape fantastic idea, I like it. and with that we could also monitor how engineers don't use the library correctly .
I'va made your changes suggested with 9678047 . Added the ["bufflog_error" => "XXXX"] fields, so we could follow how and how often the library being missused

Comment on lines +48 to +53
echo json_encode([
"message" => "Can't find \DDTrace\GlobalTracer class. Did you install the Datadog APM tracer extension? It will allow you to have logs enriched with traces making troubleshooting easier. If you run a cli mode service (such as a worker), did you set the DD_TRACE_CLI_ENABLED env variable?",
"level" => 300,
"level_name" => "WARNING",
"context" => ["bufflog_error" => "no_tracer"]
]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the logger isn't ready yet, we have to do this manually

@erickhun erickhun merged commit 45f8fb1 into master Mar 11, 2020
@erickhun erickhun deleted the task/type-safe branch March 11, 2020 03:19
Copy link

@colinscape colinscape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @erickhun - I left a couple more thoughts for improvements/enhancements that you could potentially consider. 😀

@erickhun erickhun mentioned this pull request Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants