danger / swift

⚠️ Stop saying "you forgot to …" in code review
https://danger.systems/swift/
MIT License
1.04k stars 135 forks source link

Prevent empty SwiftLint violation response from failure #596

Closed pouyayarandi closed 8 months ago

pouyayarandi commented 8 months ago

Problem

In some cases like empty merge request (merge request with no changes) SwiftLint fails as its response is empty and JSONDecoder got Unexpected end of file error.

Error deserializing SwiftLint JSON response (): dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Unexpected end of file" UserInfo={NSDebugDescription=Unexpected end of file})))

Solution

This PR solves the issue with checking whether response is empty or not. If the response is empty it bypasses decoding and returns an empty array of violations.

pouyayarandi commented 8 months ago

Solves #266

f-meloni commented 8 months ago

Can you please also update the CHANGELOG?

pouyayarandi commented 8 months ago

@f-meloni Done