qri-io / qri

you're invited to a data party!
https://qri.io
GNU General Public License v3.0
1.11k stars 66 forks source link

Bug: `/body` endpoint returns malformed data when returning peer's body #532

Closed ramfox closed 6 years ago

ramfox commented 6 years ago

curl -X GET http://localhost:2503/body/at/ipfs/QmPtQDdt8UJJmorRacAna2vjyzVP8KQi35HWPXNGpSemrf?page=1

gets this response:

{
  "meta": {
    "code": 500,
    "error": "repo: not found"
  }
}{"data":{"path":"/ipfs/QmUezaeQQWMLwmB98jAdVGCvZ3qzUAPgvNffRJDwNXrJn3","data":[["George Washington","Feb 22, 1732","Westmoreland Co., Va.","Dec 14, 1799","Mount Vernon, Va."],["John Adams","Oct 30, 1735","Quincy, Mass.","July 4, 1826","Quincy, Mass."],["Thomas Jefferson","Apr 13, 1743","Albemarle Co., Va.","July 4, 1826","Albemarle Co., Va."],["James Madison","Mar 16, 1751","Port Conway, Va.","June 28, 1836","Orange Co., Va."],["James Monroe","Apr 28, 1758","Westmoreland Co., Va.","July 4, 1831","New York, New York"],["John Quincy Adams","July 11, 1767","Quincy, Mass.","Feb 23, 1848","Washington, D.C."],["Andrew Jackson","Mar 15, 1767","Waxhaws, No./So. Carolina","June 8, 1845","Nashville, Tennessee"],["Martin Van Buren","Dec 5, 1782","Kinderhook, New York","July 24, 1862","Kinderhook, New York"],["William Henry Harrison","Feb 9, 1773","Charles City Co., Va.","Apr 4, 1841","Washington, D.C."],["John Tyler","Mar 29, 1790","Charles City Co., Va.","Jan 18, 1862","Richmond, Va."],["James K. Polk","Nov 2, 1795","Mecklenburg Co., N.C.","June 15, 1849","Nashville, Tennessee"],["Zachary Taylor","Nov 24, 1784","Orange County, Va.","July 9, 1850","Washington, D.C"],["Millard Fillmore","Jan 7, 1800","Cayuga Co., New York","Mar 8, 1874","Buffalo, New York"],["Franklin Pierce","Nov 23, 1804","Hillsborough, N.H.","Oct 8, 1869","Concord, New Hamp."],["James Buchanan","Apr 23, 1791","Cove Gap, Pa.","June 1, 1868","Lancaster, Pa."],["Abraham Lincoln","Feb 12, 1809","LaRue Co., Kentucky","Apr 15, 1865","Washington, D.C."],["Andrew Johnson","Dec 29, 1808","Raleigh, North Carolina","July 31, 1875","Elizabethton, Tenn."],["Ulysses S. Grant","Apr 27, 1822","Point Pleasant, Ohio","July 23, 1885","Wilton, New York"],["Rutherford B. Hayes","Oct 4, 1822","Delaware, Ohio","Jan 17, 1893","Fremont, Ohio"],["James A. Garfield","Nov 19, 1831","Cuyahoga Co., Ohio","Sep 19, 1881","Elberon, New Jersey"],["Chester Arthur","Oct 5, 1829","Fairfield, Vermont","Nov 18, 1886","New York, New York"],["Grover Cleveland","Mar 18, 1837","Caldwell, New Jersey","24-Jun-08","Princeton, New Jersey"],["Benjamin Harrison","Aug 20, 1833","North Bend, Ohio","13-Mar-01","Indianapolis, Indiana"],["William McKinley","Jan 29, 1843","Niles, Ohio","14-Sep-01","Buffalo, New York"],["Theodore Roosevelt","Oct 27, 1858","New York, New York","6-Jan-19","Oyster Bay, New York"],["William Howard Taft","Sep 15, 1857","Cincinnati, Ohio","8-Mar-30","Washington, D.C."],["Woodrow Wilson","Dec 28, 1856","Staunton, Virginia","3-Feb-24","Washington, D.C."],["Warren G. Harding","Nov 2, 1865","Morrow County, Ohio","2-Aug-23","San Francisco, Cal."],["Calvin Coolidge","July 4, 1872","Plymouth, Vermont","5-Jan-33","Northampton, Mass."],["Herbert Hoover","Aug 10, 1874","West Branch, Iowa","20-Oct-64","New York, New York"],["Franklin Roosevelt","Jan 30, 1882","Hyde Park, New York","12-Apr-45","Warm Springs, Georgia"],["Harry S. Truman","May 8, 1884","Lamar, Missouri","26-Dec-72","Kansas City, Missouri"],["Dwight Eisenhower","Oct 14, 1890","Denison, Texas","28-Mar-69","Washington, D.C."],["John F. Kennedy","29-May-17","Brookline, Mass.","22-Nov-63","Dallas, Texas"],["Lyndon B. Johnson","27-Aug-08","Gillespie Co., Texas","22-Jan-73","Gillespie Co., Texas"],["Richard Nixon","9-Jan-13","Yorba Linda, Cal.","22-Apr-94","New York, New York"],["Gerald Ford","14-Jul-13","Omaha, Nebraska","26-Dec-06","Rancho Mirage, Cal."],["Jimmy Carter","1-Oct-24","Plains, Georgia","",""],["Ronald Reagan","6-Feb-11","Tampico, Illinois","5-Jun-04","Los Angeles, Cal."],["George Bush","12-Jun-24","Milton, Mass.","",""],["Bill Clinton","19-Aug-46","Hope, Arkansas","",""],["George W. Bush","6-Jul-46","New Haven, Conn.","",""],["Barack Obama","4-Aug-61","Honolulu, Hawaii","",""],["Donald Trump","14-Jun-46","New York, New York","",""]]},"meta":{"code":200},"pagination":{"nextUrl":"/body/at/ipfs/QmPtQDdt8UJJmorRacAna2vjyzVP8KQi35HWPXNGpSemrf?page=1"}}

First, the /body endpoint calls CanonicalizeDatasetRef, which returns a 500 repo: not found error. This error is being written to the ResponseWriter. It then proceeds to call LookUpBody which gets the peer's dataset body and returns it.

This response cannot be parsed correctly by the frontend.

ramfox commented 6 years ago

@dustmop I can close this bug with a work around for now, but it doesn't get to heart of this issue.

You mentioned that qri body will be subsumed into qri get, is that still the plan?

What do we think about a world where we pass lib.LookupBody a datasetRef, rather than just a path and handle all the canonicalizing/handling local vs peer down there.

dustmop commented 6 years ago

Ah, sorry, just saw the comment here. My recommendation for the better (and still easy) fix is in the PR. Even if body will soon get merged, the api will still probably have some specific code so this should be fixed.