Debugging JSON connections
For the majority of its integrations (JIRA, GitHub, Bitbucket, GitLab, …), the corresponding platform will be accessed over a REST API which is based on JSON. In case of parsing problems, it may be helpful to debug log sent and received JSON objects. To do so:
-
create a temporary debug output directory on your hard disk, which is writable for SmartGit (e.g.
c:/temp/json
) -
add following line to smartgit.properties for which you will replace
<absolute-path-to-debug-directory>
by your directory’s path (on Windows, be sure to use forward-slashes instead of back-slashes)smartgit.json.debugDir=<absolute-path-to-debug-directory>
Example:
smartgit.json.debugDir=c:/temp/json
-
optionally, you can also specify to log sent and received HTTP headers to the debug output file:
smartgit.json.debugHeaders=true
Note
Debug headers are not supported for certain types of integrations, notably not for GraphQL-related integrations, such as GitHub.
Note
If enabled, the debug log of sent headers will also include
Authorization
and similar headers which contain your username/password or similar credentials. Thus, be sure to remove the debug output files from your disk as soon as you have finished the debugging. -
shutdown SmartGit
-
get rid of
logs/log.txt*
from SmartGit’s Settings directory (it’s the same directory wheresmartgit.properties
is located) -
restart SmartGit to have the changes take effect
- invoke the problematic operation:
- in case of parsing problems, SmartGit will report the debug output file for the failed operation in the error message
- check the debug output directory for sent and received JSON objects:
- for a single request, there may be an
in
files containing the received content, anout
file containing the sent content and anerr
file containing the received error; there may also be severalgraphql.*
-files - all files belonging to the same request will be labeled by a unique timestamp
- depending on the server side and error, not all of these files may be present
- for a single request, there may be an
- if asked so, send all files compressed to [email protected], be sure to also include SmartGit’s log files!
- copy over
logs/log.txt*
from the Settings directory to the temporary debug output directory - compress all files into a single archive using either ZIP, 7z or TAR-GZ
- copy over
Replicating problems with curl from command line: example “Debug why Create GitHub Pull Request fails”
-
On the GitHub website, go to your account Settings, Developer settings, Personal access tokens and create a personal access token which has at least all repo scopes.
-
In SmartGit, Preferences, Hosting Providers, open the GitHub configuration and paste this token into the Token input field.
-
Verify that the tokens work, e.g. by clicking the GitHub icon in the Branches view (Log window) which should start refreshing and displaying pull requests.
-
Confirm that Create Pull Request still fails with your token.
-
Exit SmartGit.
-
Enable JSON debug logging, as explained above.
-
Open SmartGit and retry to Create Pull Request; this should result in an “.out.json” file like:
https://api.github.com/repos/someone/priv/pulls {"head":"someone:feature\/XYZ-123","title":"file added","body":"","base":"master"}
-
Copy this file to another temporary directory and rename it to
body.json
, likec:/temp/curl/body.json
and remove the first line which is the actual URL to be opened:{"head":"someone:feature\/XYZ-123","title":"file added","body":"","base":"master"}
-
From command line,
cd
to this directory and invoke:curl -k -H "Authorization: token <token>" -H "Content-Type: application/json" --data @body.json <url> > out.log
For the above command, replace
<token>
by your personal access token and<url>
by the URL you had removed from the JSON file before. For example, a real call might look like:curl -k -H "Authorization: token 69460770e6251fea183b229c9a89fac616c641f9" -H "Content-Type: application/json" --data @body.json https://api.github.com/repos/someone/priv/pulls > out.log 2> err.log
-
Check
out.log
anderr.log
to see the results.
GitHub: replicating problems with the GraphQL explorer
SmartGit (since version 22.1) is using GitHub’s GraphQL API to access metadata from GitHub. The JSON out
-file (see above) will contain the sent GraphQL query. For example:
{"operationName":"RepositoryInfo","variables":{"user":"ocornut","project":"imgui"},"query":"query RepositoryInfo($user: String!, $project: String!) { repository(owner: $user, name: $project) { __typename ...RepositoryResult } } fragment RepositoryResult on Repository { id name url sshUrl hasIssuesEnabled owner { login } defaultBranchRef { name } parent { name owner { login } } }"}
After pretty printing the content of the out file it will look similar to:
{
"operationName": "RepositoryInfo",
"query": "query RepositoryInfo($user: String!, $project: String!) { repository(owner: $user, name: $project) { __typename ...RepositoryResult } } fragment RepositoryResult on Repository { id name url sshUrl hasIssuesEnabled owner { login } defaultBranchRef { name } parent { name owner { login } } }",
"variables": {
"project": "imgui",
"user": "ocornut"
}
}
You can now log into GitHub’s GraphQL Explorer and run the query there to see whether the error is reproducible. For that, you will have to only copy over the actual query term of the JSON logging, or with other words drop the leading "query":"
and trailing ",
. For the above example, this is what you will enter into the GraphQL Explorer:
query RepositoryInfo($user: String!, $project: String!) { repository(owner: $user, name: $project) { __typename ...RepositoryResult } } fragment RepositoryResult on Repository { id name url sshUrl hasIssuesEnabled owner { login } defaultBranchRef { name } parent { name owner { login } } }
You also need to specify the variables in the variables tab of the GraphQL Explorer, just copy the content of the variables object and insert it in the variables field. For the above example it should read:
{
"project": "imgui",
"user": "ocornut"
}