Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error when building , getting : "suspect or "

Tags:

debugging

go

I'm encountering a build issue with go. I'm wondering if it's a bug in the compiler or a problem with the code.

// removed the error handling for sake of clarity 

file, _ := c.FormFile("file")
openedFile, _ := file.Open()
buffer := make([]byte, 512)
n, _ := openedFile.Read(buffer)

contentType := http.DetectContentType(buffer[:n])

// doesn't work

if contentType != "image/jpeg"  || contentType != "image/png" {
  return 
}

// works 

if contentType != "image/jpeg" {
    return
}
else if contentType != "image/png" {
    return
}

error suspect or: contentType != "image/jpeg" || contentType != "image/png"

fyi " c.FormFile("file") " is form Gin gonic. but it shouldnt really matter.

like image 345
jayD Avatar asked Jun 19 '20 12:06

jayD


People also ask

What does suspect mean in SQL Server?

When SQL server suspects the primary filegroup of the database to be damaged or if the database file is missing, the database status is set to ‘Suspect’. Also, there are a wide range of errors that could result in SQL database in suspect mode .

What does it mean when a database is in suspect mode?

When connecting to the SQL Server database for instance, if you find a message indicating that the database is in the suspect mode, it means the server suspects the primary filegroup of the database to be damaged.

How to fix ‘SQL Server suspect database’ issue?

It describes step-wise instructions to fix the ‘SQL server suspect database’ issue by running Transact-SQL (T-SQL) commands in SQL Server Management Studio (SSMS). Also, it provides an alternative solution to restore the database using a SQL Recovery tool. When SQL database goes into suspect mode, it becomes inaccessible.

What are the most common build errors in angular?

Many common build errors may occur as a result of rebuilding your app while using ng serve or running ng build or ng build --prod directly. Module Not Found One of the most common Angular errors is the infamous "Module not found" error.


1 Answers

What you see is a compiler warning, but the app will run.

Your condition is always true:

contentType != "image/jpeg"  || contentType != "image/png" 

You compare a string variable to 2 different string values (using not equal), so one of them will surely be true, and true || false is always true.

Most likely you need logical AND: I assume you want to test if the content type is neither JPEG nor PNG:

if contentType != "image/jpeg" && contentType != "image/png" {
    return 
}
like image 156
icza Avatar answered Oct 19 '22 11:10

icza